Text Tools

Caesar cipher: why only 25 keys means anyone can crack it

The Caesar cipher shifts every letter by a fixed number. With a shift of 3, HELLO becomes KHOOR. It is fun and historic, but there are only 25 useful shifts, so a computer (or a patient person) can try them all in seconds. Here is how it works and why it fails.

By the Toolcloak team8 October 20263 min read
In this article
  1. How it works
  2. Why it is so weak
  3. A bigger key space still is not enough
  4. What modern encryption does differently
  5. Where the Caesar cipher is still used
  6. A quick challenge

Julius Caesar is said to have used a simple trick to hide military messages: shift every letter a few places along the alphabet. The method is easy to learn and a good first step into cryptography. It is also easy to break, and seeing why teaches the key idea behind every secure system.

How it works

Write the alphabet twice, one row shifted. To encrypt, find each letter in the top row and replace it with the letter below it. To decrypt, go back the same number of places. The shift amount is the key.

PlainHELLO
Shift 3KHOOR
Shift 13 (ROT13)URYYB

Shift 13 is special: applying it twice returns the original, because 13 + 13 = 26 letters.

Type a message and a shift to encode or decode it.Open Caesar Cipher & ROT13

Why it is so weak

A shift of 0 does nothing and a shift of 26 returns to the start, so only shifts 1 to 25 change the text. An attacker does not need to guess the key. They try all 25 and read the one that makes sense.

The whole key space: 25 useful shifts
  • Shifts to try25
Breaking a Caesar cipher by brute force
  1. 1Take the ciphertextFor example KHOOR.
  2. 2Try shift 1 to 25Decode with each one. It takes seconds by hand and microseconds by computer.
  3. 3Read the resultsOnly one will be a real word. Shift 3 gives HELLO.

A bigger key space still is not enough

What if each letter could be swapped for any other, not just by a fixed shift? That is a general substitution cipher, with 26! (26 factorial) possible keys, about 4.03 × 10²⁶. Brute force is hopeless. But the cipher still leaks, because the language does.

How often each letter appears in typical English text (%)
12.7%E9.1%T8.2%A7.5%O7%I6.7%N6.3%S

These are approximate averages for English. In a long ciphertext, the most common symbol is likely E, the next T, and so on. That is enough to start cracking the cipher.

Count the letters in the ciphertext and match the most common to E, T and A. Then use common words like THE and AND to refine. A few paragraphs of text usually give it away. This is frequency analysis, known for over a thousand years.

What modern encryption does differently

Caesar versus modern encryption
Caesar cipher25 keys
  • Same shift for every letter
  • Pattern of the language shows through
  • Cracked by hand in minutes
Modern ciphers like AES-2562²⁵⁶ keys
  • Scrambles bits, not letters
  • Output looks random
  • Brute force is infeasible

AES-256 has about 1.2 × 10⁷⁷ keys. And the security does not rest on keeping the method secret, only the key.

Where the Caesar cipher is still used

  • Puzzles and escape rooms. Easy to make and to solve.
  • ROT13 on forums. Used to hide spoilers so you must choose to read them. It is not security.
  • Teaching. It shows keys, encryption and brute force in one small example.
  • Obfuscation. It sometimes hides text from a casual look. Do not use it for passwords. See password entropy for what real strength looks like.

A quick challenge

Decode WKLV LV IXQ with a shift of 3. Go back three letters for each: W→T, K→H, L→I, V→S. The message is THIS IS FUN. Try the tool above with your own message and share the shift with a friend.

Questions people ask

How does the Caesar cipher work?

Each letter is replaced by the letter a fixed number of places further along the alphabet, wrapping around after Z.

How many keys does a Caesar cipher have?

25 useful shifts (1 to 25). Shift 0 and 26 leave the text unchanged.

How do you break a Caesar cipher?

Try all 25 shifts and read the one that gives real words, or use letter frequency to guess the shift.

What is ROT13?

A Caesar cipher with a shift of 13. Applying it twice returns the original text.

Is the Caesar cipher secure?

No. It is easy to crack and should only be used for fun or learning.