Section 3: Classical Cryptography

Classical cryptography is the pen-and-paper era: every cipher in this section could be run by a clerk with a pencil, a keyword, and a bit of patience. Julius Caesar shifted letters to protect military orders; Renaissance diplomats used the Vigenère cipher; the British army carried Playfair into the field as late as World War I. Every single one of these ciphers is completely broken today — a laptop breaks any of them in milliseconds, and most fall to careful hand analysis. So why study them?

Because they teach the core ideas of the whole field in miniature. Classical ciphers introduce the two fundamental operations that all modern ciphers still combine — substitution (replace symbols with other symbols) and transposition (rearrange symbols without changing them). They force you to think about key management: how do sender and receiver agree on a secret, and how much secret is enough? And they are the birthplace of cryptanalysis — the art of breaking ciphers — which is where you learn the most important lesson in cryptography: a cipher is only as strong as the statistical fingerprints it fails to erase.

How to read this page
Every cipher below has a live encoder/decoder. Do not just read — type your own name into each widget, encrypt it, break it. Ten minutes of hands-on play teaches more than an hour of reading.

The Caesar cipher

The Caesar cipher is the simplest possible substitution cipher: pick a shift value k, and replace every letter with the letter k positions later in the alphabet, wrapping around at Z. Encryption is C = (P + k) mod 26 and decryption is P = (C − k) mod 26, where letters are numbered A=0 through Z=25. Suetonius reports that Caesar himself used a shift of 3.

Worked example with shift 3, encrypting ATTACK AT DAWN:

plain : A T T A C K   A T   D A W N
shift : +3 each letter, wrap Z -> A
cipher: D W W D F N   D W   G D Z Q

A shifts to D, T shifts to W, and so on. To decrypt, shift back by 3 (or equivalently forward by 23, since −3 ≡ 23 (mod 26)).

plain cipher ABCDEFGHIJKLMNOPQRSTUVWXYZ DEFGHIJKLMNOPQRSTUVWXYZABC shift +3 (wrap Z → A) A→D T→W X→A
The Caesar cipher with shift 3 as a fixed two-row lookup: every plain letter (top) maps straight down to the letter three positions later (bottom). Note the wraparound at the right edge — X, Y, Z map to A, B, C. Decryption is the same table read upward.

The fatal flaw is the keyspace: there are only 25 useful shifts (shift 0 changes nothing). An attacker does not need cleverness — they try all 25 and read off the one that looks like language. This is a brute-force attack, and it works whenever the keyspace is small enough to enumerate. Try it yourself with the button below.

Caesar cipher encoder / decoder
Result appears here. Try encrypting your name.

Monoalphabetic substitution

If 25 keys is too few, why not use any scrambled alphabet as the key? A monoalphabetic substitution cipher maps each plaintext letter to a fixed, arbitrary ciphertext letter — for example A→Q, B→X, C→M, and so on through all 26 letters. The key is the whole permutation, and the number of possible permutations is

26! = 403,291,461,126,605,635,584,000,000  (about 4 x 10^26, roughly 2^88)

That is comparable to the keyspace of a modern 88-bit cipher — far beyond any brute-force search, then or now. And yet monoalphabetic substitution has been routinely broken since the 9th century. Newspaper readers solve them for fun as "cryptograms."

This is one of the most important lessons in cryptography: keyspace size is necessary but nowhere near sufficient for security. A large keyspace only rules out one specific attack (exhaustive search). If the cipher leaks structure — if patterns in the plaintext survive into the ciphertext — an attacker can exploit that structure and never search the keyspace at all. Monoalphabetic substitution leaks structure catastrophically: every E in the plaintext becomes the same ciphertext letter, every T becomes the same letter, and so on. The disguise changes the letters but perfectly preserves their statistics. Which brings us to the attack that kills it.

Frequency analysis

Letters in natural language are wildly non-uniform. In typical English text, E accounts for about 12.7% of all letters, while Z is under 0.1%. The distribution is so stable that a few hundred characters of text is usually enough to identify the most common letters reliably.

LetterFrequencyLetterFrequency
E12.7%S6.3%
T9.1%H6.1%
A8.2%R6.0%
O7.5%D4.3%
I7.0%L4.0%
N6.7%U2.8%
12.7% 12.7 9.1 ABCDEFGHIJKLMNOPQRSTUVWXYZ E T A O I N — the six workhorses (≈51% of all English text)
Typical English letter frequencies. The lopsided shape is the cryptanalyst's weapon: any cipher that maps each letter to one fixed symbol reproduces this exact silhouette with the labels shuffled. Use the live analyzer below to see it happen on a real ciphertext.

The method was first described by the Arab polymath Al-Kindi in the 9th century, in his Manuscript on Deciphering Cryptographic Messages — arguably the founding document of cryptanalysis. His procedure still works today:

  1. Count the frequency of every letter in the ciphertext.
  2. Match the most frequent ciphertext letters to the most frequent letters of the language (the top cipher letter is probably E, the next probably T, and so on).
  3. Fill in tentative guesses and look for word patterns — a three-letter word ending in your guessed E is very likely THE; a one-letter word is A or I.
  4. Iterate: each confirmed letter constrains the rest, and the solution snowballs.

Digraph frequencies help too: TH, HE, IN, ER, AN are the most common English letter pairs, and doubled letters are usually LL, EE, SS, OO, or TT. The widget below counts letter frequencies in any text you paste and charts them against expected English. It is preloaded with a genuine monoalphabetic ciphertext — analyze it and notice how the shape of the bar chart still screams "English," just with the labels shuffled.

Frequency analyzer
Bars show your text (top) vs typical English (bottom, dimmed). The tallest bar in the sample maps to E.
Break the sample
In the preloaded ciphertext, T is the most common cipher letter — so guess T→E. The next most common is W — guess W→T. Now the frequent three-letter word WKT reads T_E... so K→H. Keep going and the message falls apart in minutes. That is Al-Kindi's snowball.

The Vigenère cipher: polyalphabetic substitution

The obvious fix for frequency analysis: stop using one substitution alphabet. The Vigenère cipher (16th century, named for Blaise de Vigenère though the strongest form is due to Giovan Battista Bellaso) uses a keyword to select a different Caesar shift for each letter. Conceptually you use the tableau: a 26×26 grid whose row i is the alphabet shifted by i. To encrypt, write the keyword repeatedly over the plaintext; each key letter picks a row, and each plaintext letter picks a column; the cell where they meet is the ciphertext letter. Numerically: C = (P + K) mod 26, with K cycling through the keyword.

Worked example: encrypt HELLO with key KEY.

plain : H  E  L  L  O        H=7  E=4  L=11 L=11 O=14
key   : K  E  Y  K  E        K=10 E=4  Y=24 K=10 E=4
sum   : 17 8  35 21 18       mod 26 -> 17 8 9 21 18
cipher: R  I  J  V  S

Notice the crucial property: the two Ls in HELLO encrypt to different letters (J and V), because they line up with different key letters. Simple frequency analysis is smeared flat — each plaintext letter can appear as several ciphertext letters. For roughly 300 years the Vigenère was known as le chiffre indéchiffrable, the unbreakable cipher.

plain key cipher H E L L O K E Y K E keyword repeats +10 +4 +24 +10 +4 R I J V S same plain letter L, different key letters → different ciphertext (J vs V)
Vigenère = one Caesar shift per key letter. The keyword KEY (K=+10, E=+4, Y=+24) cycles over HELLO; each column is C = (P + K) mod 26. The orange columns show why frequency analysis is smeared flat — and the repeating key (dashed boxes) is exactly the periodic structure Kasiski and Friedman later learned to detect.

It fell to two ideas in the 19th and 20th centuries:

Either way, the "unbreakable" cipher reduces to a stack of Caesar ciphers. The deep lesson: a repeating key is a periodic structure, and periodic structure is detectable. (Stretch the key to be as long as the message, truly random, and never reused, and you get the one-time pad — genuinely unbreakable, and covered in Section 4.)

Vigenère encoder / decoder
Try the worked example, then a longer message with a short key — can you spot repeated ciphertext fragments?

Transposition ciphers

Substitution replaces letters; transposition keeps every letter unchanged but shuffles their positions. The ciphertext is an anagram of the plaintext — which means letter frequencies are exactly those of normal English (a quick tell that you are looking at a transposition rather than a substitution cipher).

Rail fence

Write the message diagonally down and up across k "rails," then read the rails off row by row. Encrypting WEAREDISCOVERED with 3 rails:

rail 1: W . . . E . . . C . . . R . . .
rail 2: . E . R . D . S . O . E . E . D
rail 3: . . A . . . I . . . V . . . D

read off rows: WECR + ERDSOEE + AIVD
cipher: WECRERDSOEEAIVD

The key is just the rail count, so the keyspace is tiny — brute force again. Decryption reverses the process: compute how many letters land on each rail, slice the ciphertext into rails, and walk the zigzag reading one letter from the appropriate rail at each step.

Columnar transposition

Stronger and historically important: write the plaintext into a grid under a keyword, then read the columns out in alphabetical order of the keyword letters. Encrypting MEETMEATNOON under the key ZEBRA:

key   :  Z  E  B  R  A
order :  5  3  2  4  1     (alphabetical rank of each key letter)
        ------------------
row 1 :  M  E  E  T  M
row 2 :  E  A  T  N  O
row 3 :  O  N  X  X  X     (X pads the last row)

read columns in order 1,2,3,4,5:
  A-col: MOX   B-col: ETX   E-col: EAN   R-col: TNX   Z-col: MEO
cipher: MOXETXEANTNXMEO
ZEBRA (5)(3)(2)(4)(1) key + alphabetical rank MEETM EATNO ONXXX write in rows read 1st 5th3rd2nd4th read columns in key order: 1 A-col → MOX 2 B-col → ETX 3 E-col → EAN 4 R-col → TNX 5 Z-col → MEO cipher: MOX ETX EAN TNX MEO out:
Columnar transposition of MEETMEATNOON under ZEBRA: write the plaintext into the grid row by row (cyan), then read whole columns out in the alphabetical order of the key letters (A first, Z last — orange). Every letter survives unchanged; only positions move, which is why the ciphertext keeps normal English letter frequencies.

Columnar transposition (often applied twice, as "double transposition") was used seriously into World War II. It falls to anagramming attacks: guess the column count, slice the ciphertext into columns, and rearrange columns until common digraphs like TH and HE appear across the rows.

Rail fence encoder / decoder
Encrypt the sample, then decrypt the result to round-trip it.

The Playfair cipher

Invented by Charles Wheatstone in 1854 (and named for Lord Playfair, who promoted it), Playfair was the first widely-used digraph cipher: it encrypts letters two at a time. Attacking pairs is much harder than attacking single letters — there are 26 single letters but about 600 digraphs, so far more ciphertext is needed for frequency analysis. The British army used it as a field cipher in the Boer War and WWI.

Grid construction. Take a keyword, drop duplicate letters, and write it into a 5×5 grid, then fill the rest with the remaining alphabet in order. Since 26 letters do not fit in 25 cells, I and J share a cell (J is written as I). For the keyword MONARCHY:

M O N A R
C H Y B D
E F G I K     (I and J share this cell)
L P Q S T
U V W X Z

Preparing the plaintext. Strip non-letters, replace J with I, and break the text into pairs. If a pair would contain the same letter twice (like the LL in BALLOON), insert an X between them; if the final pair is short one letter, pad with X.

The three digraph rules. For each pair, locate both letters in the grid:

Worked example with the MONARCHY grid, encrypting HIDE → pairs HI DE:

HI : H at row 2 col 2, I at row 3 col 4  -> rectangle
     H -> same row as H, column of I  = B
     I -> same row as I, column of H  = F
     HI -> BF

DE : D at row 2 col 5, E at row 3 col 1  -> rectangle
     D -> row of D, column of E = C
     E -> row of E, column of D = K
     DE -> CK

HIDE -> BFCK

Playfair still leaks: digraph frequencies survive (TH is still the most common pair), a digraph and its reverse always encrypt to a pair and its reverse (ER/RE become, say, XY/YX), and with a few hundred letters of ciphertext, digraph frequency analysis plus grid reconstruction breaks it by hand. It was considered acceptable for field use only because the information was stale by the time the enemy broke it.

Playfair cipher — grid builder and encoder / decoder
The grid above updates as you type the keyword. J is merged into I; doubled letters and odd length are padded with X.

Why classical ciphers fail

The three fatal weaknesses

1. Small keyspaces. Caesar has 25 keys, rail fence a handful. Any keyspace an attacker can enumerate is no keyspace at all. Modern ciphers use keys of 128 bits or more — about 3 × 1038 possibilities.

2. Preserved statistics. Even with a huge keyspace (26! for monoalphabetic substitution), the plaintext's statistical fingerprint — letter, digraph, and word frequencies — survives into the ciphertext. Frequency analysis reads it straight off. Transposition is even worse: it preserves the letter frequencies exactly.

3. No diffusion or confusion. In every classical cipher, each ciphertext letter depends on only one or two plaintext letters and a small piece of the key. Modern ciphers make every output bit depend on every input bit and every key bit (diffusion) through many mixing rounds, and make the key relationship hopelessly complicated (confusion). Flip one plaintext bit in AES and about half the ciphertext bits flip.

Section 4 shows how modern symmetric ciphers combine substitution and transposition — the same two primitives you just learned — thousands of times over, at the bit level, to fix all three problems.

Check your understanding

Resources

bookThe Code Book — Simon Singh
The best popular history of cryptography. Chapters 1-3 cover everything on this page, including the full story of Al-Kindi, Babbage vs Vigenere, and Playfair.
videoComputerphile — Cryptography playlist
Short, sharp videos including classical ciphers, frequency analysis, and why they fail — a perfect companion to this section.
articlePractical Cryptography — Cryptanalysis
Step-by-step guides to actually breaking every cipher on this page: frequency analysis, Kasiski, index of coincidence, hill-climbing attacks on substitution and Playfair.
tooldCode.fr
Online solvers and automatic breakers for hundreds of classical ciphers — paste a mystery ciphertext and let it identify and crack it.
toolCrypTool Online
Free interactive cryptography lab in the browser: classical and modern ciphers, analysis tools, and visualizations.