## What is a Substitutional Cipher?

A substitutional Cipher is a form of cryptography, also known as Ceaser Cipher. The primary aim is to send and receive encrypted messages while the eavesdropping party will only get hold of encrypted information. It was introduced by Julius Ceaser during the American Civil War to send encrypted messages to his team to communicate over the battlefield. Substitutional Cipher works by shifting the Letter, Alphabet in the range of 0 to 25, and use it as the substitutional of it. In the Ancient War, Ceaser changed Alphabet ‘A’ with Alphabet’ D’. The distance between the Alphabet is 3 and is known as the key in the Substitutional Cipher.

## How does Encrypt Cipher work?

• Write Each Letter of Alphabets from A-Z and usually called Master Row.
• Select a Key. E.g. 3,
• According to the chosen Key-value, Count that amount of Spaces to the right. Continue to reach the alphabets until you reach the end.

• Fill in the remaining spaces by the following Alphabets. This row is Cipher Row or Cipher Lane.
• To Encrypt the Cipher, put the Master Row in parallel to Cipher Lane, and perform the Substitutional cipher over it. E.g., Dog is the targeted word to be ciphered. The ciphered word will be GRJ

A couple of other examples can be as follow

Plaintext: friend, speak

Key: E

Ciphertext: JVMIRHD, WTIEOD

## Decryption

As seen in the Encryption method, the first thing is to have a key to create a cipher. For decrypting the cipher, one should know the key as well. The process to decipher the cipher are as follow;

Decryption Key: Let’s take the previous example and continue. The Key in the Decryption will not be different but not the same. As the key is three (3), it will be inverted, which is -3 in the ongoing example.

Inversion of Tables: As seen in the Encryption Process, Master Row gets matched with Cipher Lane. In Decryption, the Cipher Lane gets compared with Master Row. The inversion of tables has three sub-methods that can decipher the ciphered text.

### 1. Simple Method:

With the previous ciphered text GRJ and decryption key -3, the simple methods work as follows.

Cipher: GRJ

Key: -3

Word:?

The Cipher Lane is to draw parallels with Master Row.  By cross-matching the words, the deciphered word is generated, which in this case, is DOG.

### 2. Move-Back Method

This method uses the cipher lane and a key to decipher the encrypted text. With the cipher lane, the key operation performs over word that is encrypted. If the key is -3, the cursor retreats three spaces to get an actual word. This method works great for small verses due to its efficiency and speed.

Let’s see how it works.

• Write the Cipher Lane

• As the key is -3; the cursor goes three letters back to identify the actual letter.

Cipher: GRJ – Key: -3

• Similarly, the same operations go for other letters as well.
• The resultant G->D, R->O,J->G
• The move-back method increases the complexity level of the code when implemented. The complexity increases due to the number of iteration over the same row depend on the word length.

### 3. Assign Numbers Methods

In this method, numbers are assigned from 0 to 26 to all the letters. Based on the assignment, mathematical calculations are performed using a formula to decrypt the word.

For example, the numbers from 0 to 26 are assigned as A=0, B=1, C=2, and so on Z=26.

The formula to extract the information is;

En(c) = [x + (-k)] mode 26

‘x’ is the value of the original letter in the alphabetic order and ‘k’ is the value of the key to decrypt the cipher is used, whereas 26 is the total number.

Note: ‘k’ will always be negative (-ve) in the formula for Decryption but positive in case of Encryption.

## Sample Code

The Simple method implementation is below, where the key will be 3.

Encryption For Lower Case

```      If (ch >= 'a' && ch <= 'z'){
ch = ch + key;
if (ch > 'z') {
ch = ch - 'z' + 'a' - 1;
}
msg[i] = ch;
```

Encryption For Lower Case

```if(ch >= 'a' && ch <= 'z') {
ch = ch - key;
if(ch < 'a'){
ch = ch + 'z' - 'a' + 1;
}
msg[i] = ch;
cout << "Decrypted message: " << msg;
```

Decryption for Upper-Case

```if(ch >= 'A' && ch <= 'Z') {
ch = ch - key;
if(ch < 'A'){
ch = ch + 'Z' - 'A' + 1;
}
msg[i] = ch;
cout << "Decrypted message: " << msg;
```

## Non-Coding approach to Decipher Substitutional Cipher

Besides the appropriate coding techniques to decipher a text, there is always a non-conventional approach that one can adapt. Some of the cracking methods are below.

• The single word across the ciphertext is usually A or I.
• The frequent symbols are usually E. Other than E, and these could also be O, A, or T in case of a short cryptogram.
• Apostrophes will always have S, D, M, T, LL, or RE after it.
• A lot of words have a repeating pattern like TH, SH, RE, CH, TR, ING, ION, and ENT. Look out for these patterns which will give a fair idea of what the key can be,
• The two-lettered word will always have one vowel and a constant. The standard two-letter words are IT, IS, IN, TO, and OF. Guessing these would often leak the key out.
• The most commonly used three-letter words are THE, FOR, AND, WAS, and HIS.

## Conclusion

However, for a long based ciphered text, it won’t be ideal for guessing the word by just going around the letters. The most common approach programmatically is to run the entire cipher with all possible keys, which is 0 tp 26 due to the availability of letters. There are a lot of Brute Force algorithms available that take up the chunk of ciphered text and decrypt then using simple method keys ranging from 0 to 26.  Sample values get displayed to the user which helps to decide which key returns a valid text.

An issue with substitutional cipher is that this follows monolithic cipher technique i.e. each plain letter gets changed to the same ciphered letter. A next level substitutional cipher is a mono-alphabetic substitution cipher where each letter is assigned a random cipher letter instead of the numeric key text. With this simple enhancement, the brute force attack jumps from 26 to 26! which increases the computation iteration to 26! = 403291461126605635584000000 or 4 * 1026 which is almost impossible.