Caesar Cipher

Caesar cipher a simple yet clever cipher that encrypts the open text by shifting each letter by three letters.


Move each letter of an open text by three. So the letter “a” becomes “d”, the letter “b” becomes “e” etc. We can create a plain table that makes encrypting easy:

a b c d e f g h i j k l m n o p q r s t u v w x y z
d e f g h i j k l m n o p q r s t u v w x y z a b c

In the first row, there are letters from the open text. In the second row, there are equivalent letters from the cipher text. Thus encrypting the word “caesar” yields resulting cipher word “fdhvdu”.


Decrypting is as easy as encrypting. We move each letter back by three letters. So the letter “d” in cipher text becomes “a” in open text etc. We can construct the table for decrypting as we did for encrypting:

a b c d e f g h i j k l m n o p q r s t u v w x y z
x y z a b c d e f g h i j k l m n o p q r s t u v w

Suppose we have a cipher word “flskhu”. Using this table we can decrypt the word to “cipher”.

Generalizing the Caesar Cipher into the Shift Cipher

The described cipher is very weak because if you know the algorithm you can always decrypt the cipher text to the open text. This is very inconvenient since the purpose of a cipher is to deny reading and understanding the cipher text. We can make the cipher slightly more secure by letting the person choose the encryption key.

Thus instead of shifting the open text by three letters, we can shift it by any number of letters. The key of the Caesar cipher is represented by a single letter. If you encrypt the letter “a” by this key, you get the key. So for example, the encryption table for key “q“ looks like this:

You can actually choose whatever key you like and see the encryption table for the given key. There is one special case: if you try key “a”, the second row will look the same as the first one. It means that when you encrypt some text using cipher key “a”, you’ll get the same text. No encryption will be done.

Use this tool to encrypt or decrypt any text you want:

How to Crack the Cipher

The Shift cipher has an obvious weakness. Because the English alphabet has 26 letters we can only choose from 26 different keys. We already know that the letter “a” yields the same cipher text thus we essentially choose from 25 different keys. The simplest way to break the cipher is to try all possible keys. Eventually we get the original message.

It is quite easy to automate such algorithm. The only thing we need is to pragmatically recognize which text is more likely to be meaningful than other texts. How can we do it?

Each language has different frequency of letters. If we harvest a lot of texts, we can analyze which letters are used more than other letters. For example, the most used letter in English is the letter “e”. The least used letter is the letter “z”. Using such analysis we get a table with frequencies for each letter:

letter frequency letter frequency
a 8.167 % n 6.749 %
b 1.492 % o 7.507 %
c 2.782 % p 1.929 %
d 4.253 % q 0.095 %
e 12.702 % r 5.987 %
f 2.228 % s 6.327 %
g 2.015 % t 9.056 %
h 6.094 % u 2.758 %
i 6.966 % v 0.978 %
j 0.153 % w 2.360 %
k 0.772 % x 0.150 %
l 4.025 % y 1.974 %
m 2.406 % z 0.074 %

We read the table as out of all letters, 8.167 % of them were letter “a”. Now we can use this data to crack the Caesar cipher. We decrypt the cipher text by all 26 letters and we compute the frequency of each letter in decrypted text. Then we compare the frequencies with the given frequencies in the table. The frequency that is closest to the frequency of English text is the original open text.

Try it! Encrypt some sentence or whole paragraph and then paste the encrypted text in the following tool and crack it! The tool is supposed to guess the encryption key on its own.