Caesar Cipher

6 min read#cryptography

Shift every letter of the alphabet by a fixed amount — the oldest cipher, and one of the easiest to break.

Contents

Caesar Cipher

The Caesar cipher encrypts a message by sliding every letter a fixed number of places down the alphabet. With a shift of k = 3, A becomes D, B becomes E, and Z wraps around to C. Julius Caesar reportedly used exactly this to shield his military dispatches.

Numbering the letters A=0, B=1, \dots, Z=25, encryption and decryption are one line of Modular Arithmetic:

c = (m + k) \bmod 26, \qquad m = (c - k) \bmod 26.

The wrap-around — the \bmod 26 — is the whole trick. The alphabet is a ring of 26 positions, and the key just rotates it.

A cipher wheel you can turn

The classic tool for a shift cipher is a cipher wheel: two concentric alphabets, the inner one rotated against the outer by the key. Line up the rings and you can read off the substitution at a glance.

Drag left↔right to set the shift k. The wheel rotates, the sample message re-encrypts live, and the frequency bars show how the telltale English peaks just slide along — handing the key to any code-breaker.

Watch the orange bar — it marks where English's dominant letter E has landed. Its position is the key. That is the fatal flaw.

Why it falls in seconds

A Caesar cipher has exactly 25 useful keys (a shift of 0 does nothing). An attacker simply tries all of them — a brute-force search so small you can do it by hand. Even faster: because the cipher only slides the alphabet, it leaves the shape of English untouched. The most common ciphertext letter is almost always a shifted E, and that one observation usually reveals k outright.

In the language of Entropy, the key carries only \log_2 25 \approx 4.6 bits of uncertainty — a rounding error against the information in a real message. There simply isn't enough secret to hide behind. The natural next step is to scramble the alphabet arbitrarily instead of merely rotating it: the Substitution Cipher.

Ciphertext encrypted with a Caesar cipher has 'W' as its most common letter. What is the most likely shift k?

See also