Caesar Cipher: The Oldest Encryption Visualized

visualization beginner ~5 min
Loading simulation...
With shift=3: A→D, B→E, C→F. 'HELLO' becomes 'KHOOR'. Only 26 possible keys — trivially breakable by brute force or frequency analysis.

With a shift of 3, each letter moves 3 positions forward in the alphabet. 'HELLO' becomes 'KHOOR'. There are only 26 possible keys, making the Caesar cipher trivially breakable.

Formula

E(x) = (x + k) mod 26
D(x) = (x - k) mod 26

How the Caesar Cipher Works

The Caesar cipher is one of the simplest and oldest known encryption techniques. Each letter in the plaintext is replaced by a letter a fixed number of positions down the alphabet. With a shift of 3, A becomes D, B becomes E, and so on. When you reach the end of the alphabet, it wraps around: X becomes A, Y becomes B, Z becomes C. Julius Caesar reportedly used this method with a shift of 3 to communicate with his generals during military campaigns.

The Mathematics of Substitution

Mathematically, the Caesar cipher operates in modular arithmetic. Encryption is defined as E(x) = (x + k) mod 26, where x is the position of the plaintext letter (A=0, B=1, ... Z=25) and k is the shift key. Decryption reverses this: D(x) = (x - k) mod 26. The 'mod 26' operation ensures the alphabet wraps around. This elegant simplicity is also its fatal weakness — there are only 26 possible keys, making brute force trivial. A modern computer can test all 26 decryptions in microseconds.

Breaking the Cipher: Frequency Analysis

Even without brute force, the Caesar cipher falls to frequency analysis — a technique discovered by Arab mathematician Al-Kindi in the 9th century. In English, the letter 'E' appears roughly 12.7% of the time, 'T' about 9.1%, and 'A' about 8.2%. These frequencies are preserved under the Caesar shift. If the most common letter in the ciphertext is 'H', the shift is likely 3 (since E + 3 = H). This simulation visualizes these frequency distributions, showing how the shifted pattern reveals the key.

Historical Significance and Legacy

Despite its simplicity, the Caesar cipher holds an important place in cryptographic history. It introduced the fundamental concept of a key-based transformation — the idea that a shared secret (the shift) allows two parties to communicate securely. This concept evolved into increasingly sophisticated ciphers: the Vigenere cipher (multiple shifts), the Enigma machine (mechanical rotors), and eventually modern encryption algorithms like AES and RSA that use keys thousands of bits long. The Caesar cipher remains a perfect teaching tool for understanding encryption fundamentals.

FAQ

What is the Caesar cipher?

The Caesar cipher is a substitution cipher where each letter is shifted by a fixed number of positions in the alphabet. Named after Julius Caesar, who reportedly used a shift of 3 to protect military messages.

How many possible keys does the Caesar cipher have?

Only 26 — one for each letter of the alphabet. This makes it trivially breakable by trying all possibilities (brute force).

Why is the Caesar cipher insecure?

Two main reasons: the tiny key space (26 keys) allows brute force, and letter frequency analysis reveals the shift because the underlying language frequencies are preserved.

What is ROT13?

ROT13 is a Caesar cipher with shift 13. Since 13 is half of 26, applying ROT13 twice returns the original text. It's used online to hide spoilers, not for security.

Sources

Embed

<iframe src="https://homo-deus.com/lab/cryptography/caesar-cipher/embed" width="100%" height="400" frameborder="0"></iframe>
View source on GitHub