About the Caesar cipher
The Caesar cipher is a monoalphabetic substitution cipher that shifts every letter of the plaintext N positions along the alphabet, wrapping Z back to A. The Roman historian Suetonius records that Julius Caesar used a shift of 3 to encode private letters to Cicero around 50 BC, replacing each Latin letter with the one three positions later. Augustus is reported to have used a shift of 1.
Today the Caesar cipher has no security value: with only 25 distinct keys, a modern computer brute-forces every shift in microseconds. Its lasting role is pedagogical. It introduces students of cryptography to the core ideas of plaintext, ciphertext, key, modular arithmetic, brute-force attack, and frequency analysis without any heavyweight mathematics. It also shows up in puzzle hunts, escape rooms, geocache challenges, and the famous ROT13 convention used on Usenet and Reddit to hide spoilers.
How it works
Each letter is treated as a number 0 to 25 (A = 0, B = 1, ..., Z = 25). Encryption adds the shift N modulo 26; decryption subtracts N modulo 26. Non-alphabetic characters (digits, spaces, punctuation) pass through unchanged. Case is preserved.
encrypt(letter) = (letter + shift) mod 26 decrypt(letter) = (letter - shift + 26) mod 26 shift range = 0 to 25 (shift 0 = identity, shift 26 = identity) ROT13 = encrypt with shift 13 (self-inverse)
- Shift: integer 1 to 25.
- Symmetric: encrypt(decrypt(x)) = x for the same shift.
- Brute-force surface: only 25 possible keys; trivially broken.
Worked example
Encrypt "HELLO" with shift 3 (Caesar's original).
- Map letters to numbers: H=7, E=4, L=11, L=11, O=14.
- Add 3 mod 26: 10, 7, 14, 14, 17.
- Map back: K, H, O, O, R.
- Output: KHOOR.
- Decrypt: subtract 3 mod 26 returns HELLO.
Alphabet to number map (shift table)
| Letter | Number | Letter | Number |
|---|---|---|---|
| A | 0 | N | 13 |
| B | 1 | O | 14 |
| C | 2 | P | 15 |
| D | 3 | Q | 16 |
| E | 4 | R | 17 |
| F | 5 | S | 18 |
| G | 6 | T | 19 |
| H | 7 | U | 20 |
| I | 8 | V | 21 |
| J | 9 | W | 22 |
| K | 10 | X | 23 |
| L | 11 | Y | 24 |
| M | 12 | Z | 25 |
To encrypt: letter number plus shift, mod 26. To decrypt: letter number minus shift, mod 26.
Breaking the cipher: frequency analysis
Brute force is the textbook attack but frequency analysis is faster and works on any length of ciphertext above about 50 characters. Every natural language has a stable letter-frequency profile. In English, E appears about 12.7 percent of the time, T about 9.1 percent, A about 8.2 percent. After encryption with shift N, those frequencies do not change, they just slide N positions along the alphabet.
| Rank | English letter | Frequency | If shifted by 3, appears as |
|---|---|---|---|
| 1 | E | 12.7% | H |
| 2 | T | 9.1% | W |
| 3 | A | 8.2% | D |
| 4 | O | 7.5% | R |
| 5 | I | 7.0% | L |
| 6 | N | 6.7% | Q |
| 7 | S | 6.3% | V |
| 8 | H | 6.1% | K |
If the most common letter in your ciphertext is H, the shift is almost certainly 3 (E to H). Cross-check with the second most common.
Common pitfalls
- Not secure for any modern purpose. Only 25 keys means a brute-force attack finishes in milliseconds. Use AES, ChaCha20, or RSA for any real confidentiality need.
- Frequency analysis breaks it faster than brute force. The most common letter in English ciphertext almost always maps to E. One peek at letter counts reveals the shift.
- Off-by-one shift confusion. A "shift of 3" can mean either A becomes D (+3) or A becomes the third letter, which is C (+2). The tool uses A becomes D, the standard convention.
- Case and punctuation. Most implementations preserve case (uppercase stays uppercase) and pass digits, spaces, and punctuation unchanged. Strict variants strip everything but letters.
- Shift 13 (ROT13) is self-inverse. Applying ROT13 twice returns the original. It is the only shift with this property because 13 + 13 = 26.
- Multilingual text. The classical Caesar applies only to a 26-letter alphabet. Extended alphabets (accented Latin, Cyrillic, Greek) need their own modulus.
- Short messages defeat frequency analysis. A 4-letter ciphertext gives almost no statistical signal, which is why short Caesar puzzles are still solvable only by brute force.
Caesar variants worth knowing
| Variant | Key idea | Key space | Still solvable? |
|---|---|---|---|
| Caesar (shift) | Single fixed shift N | 25 keys | Trivial brute force |
| ROT13 | Caesar with shift 13 | 1 key | No effort, self-inverse |
| Atbash | A to Z, B to Y, mirror | 1 key | Trivial pattern |
| Affine | (a x + b) mod 26 | 312 keys | Frequency analysis |
| Vigenere | Caesar with rotating key word | 26^len(key) | Kasiski 1863, Friedman 1925 |
| Substitution | Arbitrary letter mapping | 26! keys | Frequency + n-grams |
Vigenere held the title of "le chiffre indechiffrable" for 300 years because its key space looks astronomical, but Kasiski showed in 1863 that key length leaks from repeated ciphertext fragments. Once length is known, Vigenere reduces to a stack of independent Caesar ciphers.
Related tools and glossary
Frequently asked questions
What is the Caesar cipher?
The Caesar cipher is a substitution cipher named after Julius Caesar, who used a shift of 3 to encode military messages around 50 BC. Each letter in the plaintext is shifted N positions down the alphabet; A becomes D with a shift of 3, B becomes E, and so on, wrapping from Z back to A. It is one of the simplest classical ciphers.
What is ROT13?
ROT13 is a Caesar cipher with a shift of 13. Because the English alphabet has 26 letters, applying ROT13 twice returns the original text, which makes it self-inverse. It is widely used on the internet to hide minor spoilers, punchlines, and joke answers without security intent.
Is the Caesar cipher secure?
No. There are only 25 possible shifts (a shift of 0 leaves text unchanged), so a brute-force attack tries every shift in well under a second. Frequency analysis cracks it even faster by identifying the most common letter and assuming it maps to E. Use it for puzzles and teaching, not security.
How do I decrypt a Caesar cipher?
Apply the inverse shift. If the text was encrypted with shift 3 (A becomes D), decrypt by shifting back 3 positions or, equivalently, forward by 26 minus 3 = 23. The tool decrypts by negating the shift value automatically.
Sources
- Suetonius, Lives of the Twelve Caesars, on Julius Caesar's encrypted correspondence.
- David Kahn, The Codebreakers (Scribner, 1996), classical cryptography survey.
- Bruce Schneier, Applied Cryptography, 2nd ed., on substitution ciphers.
