top of page
Writer's pictureNerdZone

Cryptography: Secure Your Message Using Ceaser Cipher

Updated: Jun 3, 2020

“Cryptography is an enormously powerful tool!” Let’s learn the basic form of this tool and explore their thinking highway towards more advanced and complex forms. This experiment is to hide information using cryptographic techniques wherein we will encrypt the information making it impossible to recover the original data for anyone but the intended person.


Introduction:


Cryptography is the study of secret (crypto-) writing (-graphy), basically the encryption and decryption of messages. It is the science used to try to keep information secret and safe. The principle of encoding a message is to ensure that only the intended receiver understands the message. Thus, when encoding a message, it is important to define a consistent “cipher”, which is known by the recipient beforehand. A “cipher” determines how the message is encrypted.


Key in cryptography is the string or password used by the sender, using which message is encrypted so that if someone eavesdrop, they won't understand it.

Symmetric-key cryptography: where a single key is used for encryption and decryption.

Asymmetric-key cryptography: where keys are used differently for encryption and decryption. Basically there is a pair of public and private keys. The sender encrypts the message using its private key. Now the Public key is shared with the receiver to decrypt the message.


We will see an example of a basic Substitution Cipher named Ceaser Cipher.


For example:


With the right shift of 3:




Requirement:


  • Paper-Pen to complete pseudo-code

  • Your favorite code editor to complete the code


Steps:


  1. Write a pseudocode to encrypt and decrypt the message. Refer to our pseudo code example.

  2. Implement encrypt and decrypt functions

  3. Test your solution by sending a string

  4. Make it a fun game by sending a secret message to your friend and let them decrypt it using the same cipher size.



Mathematical Explanation:



encrypted_character = (input_char + cipher) mod 26

decrypted_character = (encrypted_char - cipher) mod 26

Pseudo Code:

Input: Text to be hidden, Cipher Value

Output: Encrypted Text

     1.  Define a "String" variable 
         ALPHABET="abcdefghijklmnopqrstuvwxyz"
     2.  Ask the user to enter the text to be hidden, which you 
         will store in another "String" variable TEXT
     3.  Ask the user to enter the cipher value, which you will 
         store in an "Int" variable CIPHER
     4.  Initialize a "String" variable CTEXT = ""
     5.  //Starting a loop to encrypt each character of data TEXT
     
     for (i = 0; i < TEXT.length ( ); i++)
          {
          
            //Initializing a temporary ‘Int’ variable T1 to store                       
              the character index number
            int T1 = ALPHABET.indexOf (TEXT.charAt (i))

            //Initializing a temporary ‘Int’ variable T2 to            
              calculate encrypted character index number
            int T2 = (T1 + CIPHER) % 26

            //Initializing a temporary ‘Char’ variable C to store 
              the encrypted character
            Char C = ALPHABET.charAt (T2)

            //Joining the encrypted character to the cipher text
            CTEXT = CTEXT + C
            
           }
      6.  Print Encrypted Text : CTEXT
    
 To decrypt the CTEXT use the formula: T2 = (T1 - CIPHER) % 26


Learning Opportunity:


  • The above-mentioned Encryption technique shifts the alphabet system by a predetermined amount so that the beginning letter of the encrypted message’s alphabet is different than that of the original message

  • Example: Input: TEXT = “BAD” & CIPHER = 3

  • Output: CTEXT = “EDG”

    • Each letter in the original message is shifted 3 letters forward in the alphabet. The encryption where the value of CIPHER = 3 is known as Caesar Cipher

  • Cryptography is widely used in computer science.

  • It is majorly used to secure network communication, financial, government, medical, even multiplayer games

  • Also, to securely store data on your computer, like your password keeper

  • Crypto-currencies make use of the algorithms for digital wallets.


Time Required: 30 minutes


128 views0 comments

Recent Posts

See All

Comments


bottom of page