Classical Ciphers and How They Broke
Encrypt with the Caesar and substitution ciphers, break them with brute force and frequency analysis, and see why only the one-time pad is unbreakable.
Welcome back!
Step 1 of 13Learn
Caesar's shift
Over 2,000 years ago, Julius Caesar reportedly protected military messages by shifting each letter three places down the alphabet: A becomes D, B becomes E, and at the end it wraps around, so X becomes A, Y becomes B, Z becomes C. The word ATTACK becomes DWWDFN.
Mathematically, number the letters A = 0, B = 1, ..., Z = 25. Encryption with key k is:
C = (P + k) mod 26
and decryption is P = (C − k) mod 26. The mod 26 means take the remainder after dividing by 26, which handles the wrap-around: Y (24) shifted by 3 is 27, and 27 mod 26 = 1, which is B.
This kind of arithmetic, called modular arithmetic, is clock arithmetic: on a 12-hour clock, 10 o'clock plus 5 hours is 3 o'clock, because 15 mod 12 = 3. It shows up throughout modern cryptography, including RSA and Diffie-Hellman later in this course.
The Caesar cipher's fatal weakness is its tiny key space. There are only 25 useful shifts. An attacker can simply try them all, a brute-force attack, and look for the one that produces readable text. By hand that takes a few minutes; a computer does it instantly.
Step 2 of 13Practice · Fill in the blanks
Fill in the blanks
Using a Caesar cipher with a shift of 3, the plaintext DOG encrypts to , and the ciphertext KHOOR decrypts to .
Step 3 of 13Learn
Bigger key space, same weakness
A monoalphabetic substitution cipher replaces each letter with another according to a scrambled alphabet: perhaps A→Q, B→W, C→E, and so on, with any permutation allowed. The key is the scrambled alphabet itself.
The number of possible keys is 26! (26 factorial), about 4 × 1026. Even checking a billion keys per second would take over ten billion years. Brute force is hopeless.
And yet a puzzle enthusiast with a pencil can break these ciphers in half an hour. The reason is frequency analysis, first described by the Arab scholar Al-Kindi in the 9th century.
In English, letters appear with very uneven frequencies. E is the most common, about 12–13% of letters, followed by T, A, O, I and N. The rarest are J, Q, X and Z. Common short words such as THE, AND and OF, and pairs such as TH and HE, have their own fingerprints.
A substitution cipher changes each letter's appearance but not how often it appears. If the letter W makes up 12% of a long ciphertext, W almost certainly stands for E. Three-letter groups that keep repeating are likely THE. Each guess reveals more letters, and the rest falls like a crossword.
The lesson is one of the most important in cryptography: a huge key space is necessary but not sufficient. A cipher must also hide the statistical patterns of its plaintext.
Step 4 of 13Practice · Chart
How often letters appear in English text
Substitution changes what each letter looks like, not how often it appears. That fingerprint survives encryption.
In a long ciphertext, the most common symbol most likely stands for which letter?
Tap the bar that answers the question, then press Check.
Step 5 of 13Practice · Choose one
In a long English text encrypted with a simple substitution cipher, the letter K appears far more often than any other letter. Which plaintext letter does K most likely represent?
Step 6 of 13Practice · Work it out
Slow, unoptimized software lets an attacker test 1,000 keys per second against an old cipher with a key space of 3,600,000 keys. How many minutes does it take, at most, to try every key?
Step 7 of 13Practice · Diagram
Key spaces compared (log scale)
A bigger key space only helps if the cipher has no shortcut. The substitution cipher has a huge key space and still falls to frequency analysis.
Which cipher has more keys than DES but is still trivially broken?
Tap the shape that answers the question, then press Check.
- Caesar: 26 shifts
25 useful keys. Try them all by hand in minutes.
- DES: 2^56
Brute-forced by a purpose-built machine in 1998.
- Substitution: 26!
About 4 × 1026 keys, yet broken with letter counts, not brute force.
- AES-128: 2^128
Far beyond any brute-force effort imaginable.
- AES-256: 2^256
Roughly the number of atoms in the observable universe is 1080.
Step 8 of 13Learn
Vigenère and the end of the classical era
To defeat frequency analysis, 16th-century cryptographers used several shifts in rotation. The Vigenère cipher takes a keyword such as LEMON and repeats it over the message. Each plaintext letter is shifted by the matching keyword letter (L = 11, E = 4, M = 12 and so on). Now the plaintext letter E might become P in one position and I in another, flattening the frequency counts. For about 300 years it was called le chiffre indéchiffrable, the indecipherable cipher.
It wasn't. In the 19th century, Charles Babbage and Friedrich Kasiski independently found the weakness: the keyword repeats. If the keyword has 5 letters, then every 5th letter was encrypted with the same shift. Find the keyword length, for example by spotting repeated chunks of ciphertext and measuring the distances between them, and the message splits into 5 separate Caesar ciphers, each breakable by frequency analysis.
The 20th century mechanized the idea of changing shifts. The German Enigma machine used rotating wheels to produce a different substitution for every letter, with an enormous number of settings. Polish mathematicians, then British codebreakers at Bletchley Park including Alan Turing, broke it using known plaintext (weather reports and stock phrases), operator mistakes and some of the first electromechanical computing machines. Historians credit this work with shortening World War II.
The recurring theme: every pattern, repetition or human shortcut is a crack an analyst can widen.
Step 9 of 13Tap to reveal
Encrypting ATTACK with the keyword LEMON
1. Repeat the keyword
Write LEMONL under ATTACK so each letter gets a shift: L=11, E=4, M=12, O=14, N=13, L=11.
2. Shift each letter
A+11 = L, T+4 = X, T+12 = F, A+14 = O, C+13 = P, K+11 = V.
3. Read the ciphertext
ATTACK becomes LXFOPV. The two Ts became X and F, which hides the letter frequencies.
4. The weakness
The keyword repeats every 5 letters. Kasiski found the repeat length, split the text into 5 Caesar ciphers, and broke each with frequency analysis.
Step 10 of 13Timeline
Milestones in classical cryptography
- c. 50 BCECaesar cipher
A fixed alphabet shift used for military messages.
- 9th centuryAl-Kindi describes frequency analysis
Letter statistics break any simple substitution cipher.
- 1553–1586Polyalphabetic ciphers mature
Bellaso and later Vigenère's name attach to the keyword-based cipher.
- 1863Kasiski publishes a general attack on Vigenère
Repeated keyword patterns reveal the key length.
- 1917Vernam's teletype cipher
XOR with a key tape, the basis of the one-time pad.
- 1932–1945Enigma broken
Polish and then British codebreakers read German traffic.
Step 11 of 13Learn
The one-time pad: perfect but impractical
One cipher is provably unbreakable, even against an attacker with unlimited computing power: the one-time pad.
In its modern form, plaintext and key are both strings of bits, and encryption combines them with XOR (exclusive or): 0 XOR 0 = 0, 0 XOR 1 = 1, 1 XOR 0 = 1, 1 XOR 1 = 0. XOR has a magic property: applying the same key twice gets you back where you started, since (P XOR K) XOR K = P. So decryption is the same operation as encryption.
Claude Shannon proved in 1949 that the one-time pad achieves perfect secrecy if four conditions hold:
- The key is truly random.
- The key is at least as long as the message.
- The key is never reused, not even partially.
- The key is kept completely secret.
Under those conditions, a ciphertext could decrypt to any plaintext of the same length with some key, so it reveals nothing except the length.
The catch is in the conditions. To send a 1 GB file, you must first get a 1 GB random key to the recipient securely, which is just as hard as sending the file securely. Reusing a pad is catastrophic: XOR two ciphertexts made with the same key and the key cancels out, leaving the XOR of the two plaintexts, which analysts can often unravel. During the Cold War, the US Venona project decrypted thousands of Soviet messages because some one-time pad pages had been reused.
Modern ciphers trade perfect secrecy for practicality: a short key, say 256 bits, that encrypts terabytes and is secure against any realistic amount of computing.
Step 12 of 13Practice · Work it out
A 4-bit plaintext 1011 is encrypted with a one-time pad key 0110 using XOR. What is the ciphertext? Type the four bits.
Step 13 of 13Practice · Select all that apply
Which conditions must hold for a one-time pad to provide perfect secrecy? Select all that apply.
Select all that apply.
Lesson complete!