# Caesar Cipher in Cryptography

This article is about a very well-known encryption technique: **The Caesar cipher**. In this article, we will first have a brief introduction regarding this technique and then will look into how the encryption and decryption are performed in it.

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**,

- Caesar Cipher is also known as a shift cipher.
- It is a type of symmetric-key cryptography.
- It follows the mono-alphabetic cipher, being a part of the substitution 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.

TOP Interview Coding Problems/Challenges

- Run-length encoding (find/print frequency of letters in a string)
- Sort an array of 0's, 1's and 2's in linear time complexity
- Checking Anagrams (check whether two string is anagrams or not)
- Relative sorting algorithm
- Finding subarray with given sum
- Find the level in a binary tree with given sum K
- Check whether a Binary Tree is BST (Binary Search Tree) or not
- 1[0]1 Pattern Count
- Capitalize first and last letter of each word in a line
- Print vertical sum of a binary tree
- Print Boundary Sum of a Binary Tree
- Reverse a single linked list
- Greedy Strategy to solve major algorithm problems
- Job sequencing problem
- Root to leaf Path Sum
- Exit Point in a Matrix
- Find length of loop in a linked list
- Toppers of Class
- Print All Nodes that don't have Sibling
- Transform to Sum Tree
- Shortest Source to Destination Path

Comments and Discussions

**Ad:**
Are you a blogger? Join our Blogging forum.