What is a Caesar Cipher?
The Caesar cipher is named after Julius Caesar, who reportedly used it to send secret messages to his generals. It is a type of substitution cipher: each letter in the message is replaced with a different letter by shifting it a fixed number of positions along the alphabet.
The number of positions you shift is called the key.
How It Works
With a shift of 3:
| Plain | A | B | C | D | E | ... | X | Y | Z |
|---|---|---|---|---|---|---|---|---|---|
| Cipher | D | E | F | G | H | ... | A | B | C |
So the letter A becomes D, B becomes E, and so on. When you reach the end of the alphabet, you wrap around (X→A, Y→B, Z→C).
Example: Encrypt "HELLO" with a shift of 3.
- H → K
- E → H
- L → O
- L → O
- O → R
Encrypted message: KHOOR
To decrypt a Caesar cipher, simply shift in the opposite direction by the same amount. To decrypt "KHOOR" with key 3: K→H, H→E, O→L, O→L, R→O → "HELLO".
Why It is Easy to Break
The Caesar cipher has a major weakness: there are only 25 possible keys (shifts of 1 to 25). An attacker can simply try all 25 possibilities until the message makes sense. This is called a brute-force attack.
Another method is frequency analysis: in English, 'E' is the most common letter. If 'H' appears most often in the cipher text, the shift is probably 3 (H is 3 ahead of E).
The Caesar cipher is not secure and should never be used to protect real information. It is only useful as an educational example of how basic encryption works.
ROT13
A popular variant of the Caesar cipher is ROT13, which uses a shift of 13. Because 13 + 13 = 26 (the length of the alphabet), ROT13 is its own inverse: applying it twice returns the original text. ROT13 is sometimes used on internet forums to hide puzzle spoilers.
From Caesar to Modern Encryption
The Caesar cipher shows us the key ideas behind encryption:
- A plaintext (the original message)
- An algorithm (the shifting method)
- A key (the shift amount)
- A ciphertext (the encrypted result)
Modern encryption uses the same three components, but with algorithms so complex that even the world's fastest computers cannot brute-force them in any reasonable time.
Practice Problems
Encrypt the word 'COMPUTING' using a Caesar cipher with a shift of 5. Show the substitution for each letter.
Show answer
A Caesar-encrypted message reads 'ROVVY'. A cryptanalyst tries all 25 possible keys and finds that shift 3 gives a recognisable word. What is the decrypted message?