Caesar Cipher

A classic substitution cipher that shifts letters by a fixed amount.

Family: Substitution Era: Ancient Rome Strength: Very weak

History & context

The Caesar cipher is one of the oldest and most famous encryption methods. It’s traditionally attributed to Julius Caesar, who reportedly used a shift of three for military correspondence. Historically, its value was practical: it prevented a casual reader from instantly understanding a message. Today, it is mainly used for learning, puzzle hunts, escape rooms, and as a building block for understanding stronger substitution systems. Modern cryptography considers Caesar completely insecure because the keyspace is tiny (26 possibilities) and because statistical fingerprints of the language survive encryption. Still, Caesar is *the* perfect cipher to learn first because it teaches: modular arithmetic, alphabet indexing, and how cryptanalysis (breaking ciphers) often starts with patterns and frequency.

How Caesar Cipher works

Pick an integer shift k from 0 to 25. Convert each letter into an index A=0, B=1, …, Z=25. To encode: add k (mod 26). To decode: subtract k (mod 26). Wrap-around happens automatically via mod 26: if shifting past Z, you continue from A. Most implementations leave punctuation, spaces, and digits unchanged, and only transform alphabetic characters. Some variants also shift lowercase separately (preserving case), while others normalize everything to uppercase.

Core rules

Worked example

Example 1 (classic): Plaintext: ATTACK AT DAWN Shift: 3 Ciphertext: DWWDFN DW GDZQ Example 2 (wrap-around): Plaintext: XYZ Shift: 4 Ciphertext: BCD

How to encode / decode

Step-by-step

  1. Decide whether you’re preserving punctuation/spaces and case.
  2. Choose a shift k (0–25).
  3. For each letter: map A=0..Z=25, compute (index + k) mod 26, map back to a letter.
  4. Leave non-letters unchanged (typical behavior).
  5. Double-check wrap-around: near Z you should cycle back to A.
💡 Tip: If you’re debugging an implementation: test simple cases first like A→D at shift 3, and wrap-around cases like Z→C at shift 3. Most Caesar bugs are off-by-one indexing or wrap-around mistakes.

How to break a Caesar Cipher

Caesar is one of the easiest ciphers to break because the keyspace is tiny: only 26 shifts exist. A brute-force attack tries all shifts and picks the result that looks most like natural language. Even faster, frequency analysis often reveals the shift immediately by comparing the most common ciphertext letter to the most common English letters (E, T, A, O, I, N). Practical note: for short ciphertexts (like < 20 letters), brute force is more reliable than frequency guesses, because short samples can have misleading statistics.

Practical checklist

What frequency looks like

Caesar preserves letter frequency exactly—only shifted. This means a Caesar ciphertext has nearly the same profile as English, just rotated. A bar chart of letters still has a few dominant peaks; it does *not* look flat/random. Key signals: • Index of Coincidence (IoC) stays close to English (~0.066). • Common digrams (TH, HE, IN) remain common, just shifted. • The most frequent ciphertext letter often corresponds to E (but not always for short text).

Signals to look for:
  • IoC is close to English; not close to random.
  • One or two letters dominate frequency (shifted versions of E/T/A/O).
  • Bigram frequency still has strong peaks (shifted TH/HE/IN patterns).
  • Brute force outputs will ‘snap’ into readable English for the correct shift.

Mini example

Suppose ciphertext letter frequency shows 'K' as most common. If plaintext most common letter is assumed 'E': Shift = (K - E) = (10 - 4) = 6. Try decoding with shift 6 and verify if common words appear.

Common mistakes

Variants

Practice

Best way to internalize Caesar: do a few by hand, then practice breaking unknown shifts using brute force. Try short messages (harder) and longer paragraphs (easier).

Try these prompts

FAQ

Only 26 (shifts 0–25). That’s why brute forcing is instant.
Test known examples: ATTACKATDAWN with shift 3 → DWWDFNDWGDZQ, and wrap-around like XYZ with shift 4 → BCD.
Most tools do (they only shift letters). Some puzzle variants remove spaces/punctuation first.
For long enough text, usually yes. For very short text, brute force is safer.
No. It’s educational and recreational only.