Caesar cipher
The Caesar Cipher is perhaps one of the most well-known ciphers, due to its rather simple nature. Named after Julius Caesar, dictator of the Roman Empire, it works as a very simple shift cipher.
As with any encryption system we have a method for encrypting, a method for decrypting, a secret key (think of it as the password with which the message can be obtained), and an alphabet. Since the Caesar Cipher is symmetric, we have the same key for both encryption and decryption.
For the Cesar Cipher the key is merely a number (from 1 to the length of the alphabet). The encryption is performed by taking a letter from the message and substituting it with the letter which comes in the alphabet after key steps.
Let us consider the case where we have the English alphabet with a key of 3 and the message "ATTACK ROME".
We begin by writing out the alphabet twice:
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 |
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 |
Then we shift the bottom row by 3 steps to the left (which is equivalent to looking for which letter is 3 letters ahead):
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 |
Thus in this example, A will be substituted by D (as it come 3 letters later), B with E, and so on.
So our message of ATTACK ROME will now become DWWDFN URPH.
Decrypting is performed by having the key, taking each letter in the encrypted message and looking which letter came key steps before it. For our example with key of 3, we have for decryption:
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 |
You can see that this is equivalent to the previous table, however the bottom and top row are switched (in the encryption table A maps to D, in the decryption D maps to A).
Thus the decrypted message becomes:
D -> A
W -> T
W -> T
D -> A
F -> C
N -> K
U -> R
R -> O
P -> M
H -> E
D -> A
W -> T
W -> T
D -> A
F -> C
N -> K
U -> R
R -> O
P -> M
H -> E
Normal Text:
Shift:
Encrypted Text:
Breaking the Cipher
When breaking a cipher traditionally we assume an adversary who has the goal of uncovering the secret password given some messages (and sometimes pairs of unencrypted and encrypted messages). When breaking the Caesar Cipher we will assume the adversary has access to some encrypted messages and their goal is to uncover the key by finding the original message.
The Caesar Cipher is unfortunately too simple of a cipher to be used for any practical application in our digital world. There are only 26 possible keys (passwords) one can choose - if you choose a key of 26 shifts, each letter will be encrypted by itself, so the two messages will be identical. If you choose a key of 27 or higher, your key is equivalent to some other one less than 26 (simply take modulo 26). Even a human can attempt all shifts within a day and find which decryption creates a coherent message. Computers can do this within a second. Such an approach is called a Brute Force attack, as we try every possible key in an exhaustive search, without using some smarter strategy.
Below you can find an example of a brute force solver, which assumes the original message was written in English.