# Caesar Cipher in Cryptography

Submitted by Monika Sharma, on January 17, 2020

Caesar cipher is one of the well-known techniques used for encrypting the data. Although not widely used due to its simplicity and being more prone to be cracked by any outsider, still this cipher holds much value as it is amongst the firstly developed encryption techniques which gave us the idea of developing the entire encryption and decryption process.

Now, talking about its characteristics and details, Caeser cipher is also known as "shift cipher". This is because, in this technique, we just shift the letters of the plain text to a certain number, (which is determined by the key) in a lexicographic order to obtain the ciphertext. The same number of letters in reverse lexicographic order is shifted back in the decryption process to obtain the plain text back.

The following key points can be drawn for the Caeser cipher,

### Encryption Process

Here, we assume the numbers 0-25 represent the English alphabets in lexicographic order, i.e. from a to z.

Suppose, we have number denoting the letters of plain text denoted by 'P', and a key, say 'K' (Note that it is better to choose key within the range of alphabets: 0 to 25).

Therefore, the encryption on the plain text to convert it into ciphertext is performed as follows,

```    E (P, K) = ( P + K ) mod 26
```

### Decryption Process

Here also, the numbers 0-25 represent the English alphabets in lexicographic order, i.e. from a to z, and we choose the same key 'K' that we used to encrypt our data. Suppose we denote the numbers representing the letters of the ciphertext using 'C'.

The decryption of the ciphertext to convert it back into plain text is performed as follows,

```    D (C, K) = ( C - K ) mod 26
```

### Example Problem

```    Given Plain text: 'HELLO'

Key: 3

Convert the given plain text into ciphertext:

Solution:
We write all the numbers associated with every letter of the plain text:
H   :  7
E   :  4
L   :  11
O   :  14

Therefore, applying the Caeser cipher for each letter:

E(H,3) = ( 7 + 3 ) mod 26
= 10    = K
E(E, 3) = ( 4 + 3) mod 26
=  7    = H
E(L, 3) = ( 11 + 3) mod 26
=  14   = O
E(O, 3) = ( 14 + 3) mod 26
=  7    = R

Therefore, the ciphertext that we get for the word 'HELLO' is 'KHOOR'.
```

Note: You can cross-check your answer by applying the decryption process over the ciphertext, and if it comes back to be the same as the plain text, then it means that our answer is correct.

Preparation

What's New

Top Interview Coding Problems/Challenges!