Lecture 18: The Caesar Cipher: A Puzzle from Ancient Rome

Educational infographic explaining frequency analysis in cryptography. On the left, a bar chart labeled 'Standard English Frequency' shows the relative frequencies of letters, with the bar for 'E' being the tallest, followed by 'T', 'A', etc. On the right, a block of jumbled ciphertext is shown. Arrows point from the most frequent letters in the ciphertext (e.g., 'V') to the most frequent letters on the English chart ('E'), suggesting a potential match. The style is clean, modern, and easy to understand, like a detective's evidence board. For a blog post on cryptanalysis.

Sequentia Explores: The Mathematics of Crypto

Part III: Historical Ciphers & the Dawn of Cryptanalysis

Lecture 18: The Caesar Cipher: A Puzzle from Ancient Rome

Welcome to Part III of our series! Having assembled our powerful mathematical toolkit, we are now ready to analyze our first real cryptographic system. And for that, we travel back over 2,000 years to the Roman Republic, to meet one of history’s most famous generals and one of the world’s most famous ciphers: the Caesar Cipher.

Named after Julius Caesar, who, according to the historian Suetonius, used it to protect his military communications, this cipher is a beautiful and simple introduction to the core mechanics of cryptography. It’s a classic logic puzzle that will allow us to put our knowledge of modular arithmetic into practice.

How the Caesar Cipher Works: A Simple Shift

The Caesar cipher is a type of substitution cipher, where each letter in the plaintext is replaced by a letter some fixed number of places down the alphabet.

Caesar’s preferred method was a shift of 3. This means ‘A’ becomes ‘D’, ‘B’ becomes ‘E’, ‘C’ becomes ‘F’, and so on. When you get to the end of the alphabet, you simply wrap around to the beginning.

Let’s encrypt the word “SEQUENTIA” with a shift of 3.

  • S -> T U V -> V
  • E -> F G H -> H
  • Q -> R S T -> T
  • U -> V W X -> X
  • E -> F G H -> H
  • N -> O P Q -> Q
  • T -> U V W -> W
  • I -> J K L -> L
  • A -> B C D -> D

So, the plaintext “SEQUENTIA” becomes the ciphertext “VHTXHQTWLD“. To an outsider, this looks like gibberish. But to a receiver who knows the secret, decryption is easy: just shift every letter back by 3 places.

Applying Our Mathematical Toolkit

This “wrapping around” of the alphabet should sound familiar. It’s a perfect application of modular arithmetic!

Let’s first convert our alphabet to numbers, where A=0, B=1, C=2, …, Z=25. We are now working in the world of integers mod 26.

  • Plaintext letter: P (represented as a number)
  • Key: k (the amount of the shift)
  • Ciphertext letter: C (represented as a number)

The encryption formula is a simple modular addition:
C ≡ (P + k) (mod 26)

The decryption formula is the inverse operation, modular subtraction:
P ≡ (C – k) (mod 26)

Let’s re-encrypt the letter ‘S’ with our key k=3.

  • ‘S’ is the 19th letter, so its numerical value is P = 18.
  • C ≡ (18 + 3) (mod 26)
  • C ≡ 21 (mod 26)
  • The 22nd letter (with value 21) is ‘V’. It matches our manual encryption!

Now let’s encrypt ‘Y’ with k=3.

  • ‘Y’ has the value P = 24.
  • C ≡ (24 + 3) (mod 26)
  • C ≡ 27 (mod 26)
  • The remainder of 27 ÷ 26 is 1. C = 1.
  • The letter with value 1 is ‘B’. This demonstrates the “wrap-around” perfectly.

Breaking the Caesar Cipher: The Power of Cryptanalysis

Let’s put on our eavesdropper Eve’s hat. We’ve intercepted the ciphertext “VHTXHQTWLD”. We know, according to Kerckhoffs’s Principle, that the system being used (a shift cipher) is likely known. The only thing we don’t know is the key.

How can we break this?

Method 1: Brute-Force Attack
The key is the amount of the shift. For the English alphabet, how many possible keys are there?
There are only 25 possibilities (a shift of 0 or 26 is useless).
This is a tiny keyspace! Eve can simply try every possible shift from 1 to 25 and see which one produces a readable message.

Let’s try a few shifts on “VHTXHQTWLD”:

  • Shift back 1: UGSWGPSVKC (Gibberish)
  • Shift back 2: TFRVFORUJB (Gibberish)
  • Shift back 3: SEQUENTIA (Success!)

With a keyspace of only 25, a brute-force attack against a Caesar cipher is trivial for a human, let alone a computer.

Method 2: Frequency Analysis (A More Powerful Tool)
A brute-force attack works here, but what if the language was unknown or the key was more complex? A more elegant attack is frequency analysis.

Every language has a distinct “fingerprint.” In English, the most common letters are E, T, A, O, I, N, S, H, R, D, L, U. The letter ‘E’ appears far more often than ‘Q’, ‘J’, ‘X’, or ‘Z’.

A simple substitution cipher, like the Caesar cipher, shuffles the letters, but it does not hide their frequencies. If ‘E’ is the most common letter in the original plaintext, then whatever letter ‘E’ is encrypted to will be the most common letter in the ciphertext.

Let’s analyze a longer piece of Caesar-encrypted text:
WKLV LV D VHFUHW PHVVDJH

  1. Count the letter frequencies in the ciphertext:
    • V: 4
    • H: 3
    • W: 2
    • K: 2
    • L: 2
    • D: 1
    • …and so on.
  2. Identify the most frequent ciphertext letter: ‘V’ is the most common.
  3. Make an Educated Guess: The most common letter in English is ‘E’. Let’s assume the plaintext ‘E’ was encrypted to the ciphertext ‘V’.
  4. Determine the Key: To get from ‘E’ (value 4) to ‘V’ (value 21), we need to calculate the shift k.
    • (4 + k) ≡ 21 (mod 26)
    • k ≡ (21 – 4) (mod 26)
    • k ≡ 17 (mod 26)
    • This doesn’t seem right. Let’s try the other direction.
      Let’s try a shift of 3, a common Caesar shift: (4+3) mod 26 = 7 (which is H). No. Let’s re-examine our ciphertext: WKLV LV D VHFUHW PHVVDJH.
      Let’s count again: H:3, V:3, L:2, W:2, K:2… We have a tie. Let’s assume the original text was English and try a different common letter. The word “D” is a single letter word, likely “A” or “I”.
      If ‘D’ is ‘A’, the shift is 3. Let’s test it: Decrypt WKLV with a shift of -3. W-3=T, K-3=H, L-3=I, V-3=S. THIS. It works!
      The key is 3. Decrypting the full message: THIS IS A SECRET MESSAGE.
  5. Our initial guess was wrong, but the method worked! By finding the most frequent letter (‘V’ or ‘H’), guessing it corresponds to a common English letter (‘E’ or ‘T’ or ‘A’), we can deduce a probable key and test it. For longer texts, this method is almost foolproof.

The Lessons of the Caesar Cipher
The Caesar cipher perfectly demonstrates our three pillars of security, mostly by failing at them:

  • Confidentiality: It provides only minimal confidentiality, easily broken by brute force or frequency analysis.
  • Integrity: It offers no integrity. Mallory can easily substitute letters in the ciphertext.
  • Authenticity: It offers no authenticity. Anyone can send a Caesar-encrypted message.

While it’s not a secure cipher by modern standards, it is a fantastic first step on our journey. It has introduced us to substitution, keys, brute-force attacks, and the powerful puzzle-solving technique of cryptanalysis.

In our next lecture, we’ll look at how we can improve upon this simple cipher with the Monoalphabetic Substitution Cipher—and why it still fails against the power of frequency analysis.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top