← onehappycloud

An illustrated journey through polyalphabetic ciphers

Enigma & Lorenz

The Enigma and the Lorenz machines protected the most secret German messages of the Second World War. Both rest on a five-hundred-year-old idea, which is to encipher every letter with a different alphabet. This page builds that idea up one step at a time, from a shifted alphabet to a machine with twelve wheels, and shows the mathematics that hid the messages and the mathematics that exposed them.

  1. ICaesar
  2. IIVigenère
  3. IIIEnigma
  4. IVLorenz
Rotor windows
AAA
Key
Lamp

Ten presses of the same key. The rotors turn before every letter, so each A lights a different lamp.

One alphabet

Caesar’s shift and the fingerprint every language leaves behind

ConventionThroughout Chapters I and II, plaintext is written in lower case and ciphertext in CAPITALS, as cryptographers traditionally do.

Julius Caesar, according to the historian Suetonius, wrote his private letters by replacing each letter with the one three places further along the alphabet. a became D, b became E, and so on. The rule is simple enough to carry in your head, and the reader needs to know only one number to undo it.

It helps to treat letters as numbers, with A = 0, B = 1, and so on up to Z = 25. Encryption then becomes addition, and the alphabet wraps around like the face of a clock: after Z comes A again. Mathematicians call this arithmetic modulo 26.

c = (p + k) mod 26p = (c − k) mod 26 p is the plaintext letter, c the ciphertext letter, k the key
Fig. 1The cipher wheel
3
Ciphertext
Drag the inner ring, or use the slider, to choose the key k. The outer ring is the plaintext and the inner ring the ciphertext. Hover a ciphertext letter to see where it sits on the wheel. The wheel is the modular clock itself: it has no end to fall off.

There are only 25 useful keys, so an enemy could simply try them all. The real weakness goes deeper, and it survives even when the number of keys is enormous. A general substitution, where the 26 letters are shuffled into any order, has 26! ≈ 4 × 1026 possible keys, and it still falls in minutes.

9th centuryAl-Kindi’s Manuscript on Deciphering Cryptographic Messages, written in Baghdad, is the oldest known description of frequency analysis.

The reason is that a substitution changes what the letters look like but not how often they occur. In English, E makes up about 13 percent of ordinary text, T about 9 percent, and Z less than a tenth of one percent. The Arab scholar al-Kindi described how to count the symbols in a secret message and match them against the known frequencies of the language. The shape of the letter histogram survives encryption, and a Caesar shift merely slides it sideways.

Fig. 2Sliding the fingerprint
Intercepted message (first 150 of 0 letters)
0
Decrypted with this shift
The bars show how often each letter appears in the intercepted message. The amber outlines show ordinary English, moved along by the shift you choose. When the outlines hug the bars, the shift is the key. The strip below the chart scores every shift with the χ² statistic, which adds up the squared differences between the counts you see and the counts English predicts; taller means a better fit.
The lesson

A single fixed alphabet cannot hide the letter frequencies of the language underneath.

Many alphabets

The tabula recta, a keyword, and three centuries of false confidence

MisattributedBlaise de Vigenère published a stronger autokey cipher in 1586. The repeating-keyword system that carries his name was Bellaso’s.

The answer to frequency analysis was to stop using a single alphabet. In 1553 Giovan Battista Bellaso proposed using a keyword to switch between Caesar shifts, one letter at a time. The method was later credited to Blaise de Vigenère and has carried his name ever since. For about three hundred years it was known as le chiffre indéchiffrable, the indecipherable cipher.

The tool is a square of 26 alphabets, each shifted one place further than the one above it. Johannes Trithemius described it as the tabula recta in his Polygraphia, written in 1508. To encrypt, write the keyword repeatedly above the message. Each plaintext letter picks a column, the key letter above it picks a row, and the ciphertext letter sits where they cross.

ci = (pi + ki mod n) mod 26 n is the length of the keyword, i the position in the message
Fig. 3The tabula recta
plainkeycipher
Each letter finds its column (the plaintext letter across the top) and its row (the key letter down the side). Notice that the same plaintext letter can land on different ciphertext letters, depending on which key letter sits above it. In attack, the two t’s become different letters.

The effect on the fingerprint is dramatic. Each letter of the key applies a different shift, so the E’s of the message are spread over several ciphertext letters and the tall bars of the histogram melt into each other. The longer the keyword, the flatter the result.

We can measure flatness with one number. The index of coincidence is the probability that two letters picked at random from a text are the same letter. For English it is about 0.067. For letters chosen uniformly at random it is 1/26 ≈ 0.038.

IC = Σ ni (ni − 1)N (N − 1) ni is how often letter i occurs, N the length of the text
Fig. 4The fingerprint fades
IC of plaintext0.000
IC of ciphertext0.000

A keyword of length 1 is a Caesar shift and leaves the IC unchanged. Every extra distinct letter pulls it toward the random level.

Letters ranked from most to least common. The outline is the message before encryption, the solid bars after. Try the example keywords and watch the steep English curve flatten out.

Flat is not the same as random, though. The keyword repeats. If the key has seven letters, then letters 1, 8, 15, 22 and so on were all encrypted with the same shift. Write the ciphertext in rows of seven and each column is an ordinary Caesar cipher, with the full English fingerprint intact.

Look aheadKeep this trick of writing a stream in rows of a chosen width in mind. Bill Tutte used exactly this on the Lorenz key in 1941 (Fig. 19).

In 1863 Friedrich Kasiski published a way to find the key length from repeated fragments in the ciphertext. In the 1920s William Friedman made the attack statistical. Try every possible length, split the ciphertext into that many columns, and compute the index of coincidence of each column. At the right length the columns look like English again and the IC jumps. Once the length is known, each column falls to the frequency attack from Chapter I.

Fig. 5Breaking the keyword
Ciphertext written in rows
Recovered key…
Decrypted with the recovered key

Click any bar to try that key length. A wrong length gives a wrong key and gibberish.

Each bar is the average index of coincidence of the columns when the ciphertext is written in rows of that length. The dashed lines mark English and random text. The key length is the first bar that reaches English; its multiples reach it too. Each column is then solved as a Caesar shift, which gives one letter of the keyword. Change the keyword in Fig. 4 and the attack runs again.
The lesson

A repeating key turns one hard cipher into several easy ones.

The perfect cipher

An interlude on the one-time pad, and why nobody could use it

Friedman’s attack worked because the key repeats. What if it never did? Suppose the key is a string of truly random letters, as long as the message, used once and then destroyed. This is the one-time pad. It grew out of Gilbert Vernam’s 1917 teleprinter cipher and Joseph Mauborgne’s insistence that the key be random and never reused.

In 1949 Claude Shannon proved that it cannot be broken, however much computing power the attacker has. The argument fits in the figure below. For any ciphertext and any plaintext of the same length there is exactly one key that connects them, and every key was equally likely to be chosen. The ciphertext tells the enemy nothing except its length.

Fig. 6Every message is possible

Whatever you type, the fourth pad above is the one key that turns the intercept into your message.

One intercepted ciphertext, four possible messages, four possible pads. One of them is the real message. Nothing in the ciphertext says which, because each pad was as likely as any other: P(message | ciphertext) = P(message).
Reused padsSoviet pads were occasionally used twice during the 1940s. American codebreakers in the Venona project read parts of thousands of messages as a result.

The catch is the key. It must be as long as all the traffic ever sent, delivered in advance to every radio operator, and never used twice. For an army sending thousands of messages a day, that was impossible. The machines of the next two chapters are an engineering compromise. They take a short secret setting and stretch it mechanically into a very long key that only looks random.

Enigma

Rotors, a reflector and a plugboard: a new alphabet for every keystroke

Arthur Scherbius patented the Enigma in 1918 and first sold it as a business machine. The German navy adopted it in 1926 and the army in 1928, and by the end of the war tens of thousands had been built. One operator typed on the keyboard, and for each key a lamp lit up on the board above it showing the enciphered letter. A second operator wrote the lamp letters down, and a radio operator sent them in Morse code.

The wiringThe rotor wirings used here are the historical ones for Wehrmacht rotors I to V and reflector B. Marian Rejewski worked out the first three mathematically in 1932.

Inside, each key press closes an electrical circuit. The current passes through a plugboard, then through three rotors, bounces off a reflector, comes back through the three rotors by a different route, passes through the plugboard again and lights a lamp. Each rotor is a disc with 26 contacts on each face, wired to each other in a scrambled order. On its own a rotor is just a fixed substitution alphabet. Because the rotors turn, the alphabet of the whole machine changes with every letter.

Fig. 7The signal path
Click here, then type on your keyboard
The letter’s journey
Typed
Lamps
Machine settings
LeftMiddleRight Rotor Ring Start

To decrypt, press Reset, then type the lamp letters. The same setting turns them back into the message.

Press a key, or click the figure and type. The right rotor turns before every letter. The current’s path is drawn in amber on the way in and in green on the way back from the reflector, and the lamp that lights is marked in green on the right. Each rotor’s letter ring slides as it turns, and its internal wiring moves with it. Switch to the M4 to add the U-boats’ fourth rotor.

III.1The stepping mechanism

The rotors turn like an odometer. The right rotor steps on every key press. Each rotor has a notch on its alphabet ring, and when the right rotor passes its notch it pushes the middle rotor one step. When the middle rotor passes its notch it pushes the left one.

One mechanical detail breaks the odometer pattern. The pawl that pushes the left rotor rests on the middle rotor’s notch, so when it pushes, it drags the middle rotor along as well. The middle rotor therefore steps twice in a row, once on the way into its notch position and again on the way out. This is the double step. It shortens the cycle from 263 = 17,576 positions to 26 × 25 × 26 = 16,900.

Fig. 8The double step

The red dot on each drum marks its notch position. The label under a drum says whether a pawl will push it on the next key press.

PressWindowsMoved
Rotors I, II and III, whose notches sit at Q, E and V, starting at A D U. On the second press the right rotor reaches its notch and kicks the middle rotor from D to E. On the third press the middle rotor, now at its own notch, moves again together with the left rotor.

III.2The mathematics of a scrambler

Each component of the Enigma is a permutation of the 26 letters, a rule that sends every letter to exactly one other letter. The whole machine is their composition. Write P for the plugboard, R, M and L for the right, middle and left rotors at their current positions, and U for the reflector. A letter passes through P, R, M and L, is reflected by U, and comes back through the inverses. Reading from right to left, the machine applies

E = P−1 R−1 M−1 L−1 U L M R P

A rotor that has turned s places is the same wiring seen from a shifted position. If ρ is the rotor’s wiring and C is the shift A → B → C → …, the turned rotor is C−s ρ Cs. In the language of group theory, turning a rotor conjugates its permutation by a shift, and every key press changes s.

Now group the terms. With X = L M R P the machine is

E = X−1 U X

The reflector U swaps 13 pairs of letters, so applying it twice does nothing, and it never sends a letter to itself. Two consequences follow in one line each.

Rejewski, 1932Conjugation relabels letters without changing the shape of a permutation’s cycles. Marian Rejewski used this to catalogue rotor positions by their cycle structure, which the plugboard could not disguise.
  1. The Enigma is its own inverse. E2 = X−1U X X−1U X = X−1U2X = identity. If A encrypts to Q, then Q encrypts to A at the same setting, so the machine that encrypts also decrypts. The operators liked this.
  2. No letter ever encrypts to itself. If E(x) = x, then U(Xx) = Xx, and U has no fixed points. The codebreakers liked this far more.
Fig. 9Thirteen pairs
Rotor windowsAAA
Selected pairA ↔ B
The same permutation in cycle notation

Click any letter on the circle to follow its chord.

At every setting the Enigma swaps the alphabet in 13 pairs, so each chord works in both directions. That is the involution. No chord ever loops from a letter back to itself. That is the missing fixed point. Turning the rotors reshuffles every pair.

III.3How many settings?

An army key sheet told operators which three of its five rotors to use and in what order, the ring settings, and which ten pairs of letters to connect on the plugboard. Each message also began from its own starting position. The possibilities multiply.

Fig. 10The key space
Plugboard: ways to place n cables
Most of the key space comes from the plugboard. The number of ways to connect n cables is 26! / ((26 − 2n)! · n! · 2n), which peaks at 11 cables. The Germans used 10. Ring settings are left out here because they mostly relabel the rotor positions.

At a million settings per second, trying them all would take about five million years. The Enigma was not broken by trying them all.

III.4The flaw

Bletchley Park’s codebreakers worked from cribs, pieces of plaintext they could guess. Weather reports contained WETTERVORHERSAGE, the weather forecast. Routine messages said KEINE BESONDEREN EREIGNISSE, nothing special to report. The difficulty was knowing where in the ciphertext the crib sat.

Enigma’s spacesOperators wrote X for a space and spelled out numbers, so a real crib reads like WETTERVORHERSAGE with no gaps.

Here the reflector gave the answer away. Since no letter encrypts to itself, the crib cannot sit anywhere that one of its letters lies directly over the same letter in the ciphertext. Slide the crib along the intercept below and watch positions get ruled out.

Fig. 11Dragging the crib
0
All positions
ruled out by a clashstill possiblenot tested yet
Drag the amber crib, use the slider, or pick a square in the map. Red marks a clash: the same letter above and below, which the Enigma can never produce. A single clash rules out the whole position.

A 16-letter crib survives a random position by luck with probability (25/26)16 ≈ 0.53, so this test alone removes about half of the candidates. It narrows the search, and the Bombe finished it.

III.5The Bombe

Alan Turing and Gordon Welchman designed the British Bombe in 1939 and 1940, building on the Polish bomba. With the crib placed at a candidate position, the crib and the ciphertext define a menu. This is a graph whose nodes are letters, with an edge between two letters whenever one was enciphered as the other, labelled with the step at which it happened.

The loops in the menu are what matter. Suppose the plugboard partner of E is some unknown letter. Travelling round a loop, through the rotors at each step’s position, must bring that letter back to itself. For a wrong rotor position almost no choice of partner survives the trip, and the Bombe rejects the position electrically, without anyone having to guess the plugboard.

Fig. 12The menu
Crib position0
Loops0

The menu follows the crib position chosen in Fig. 11.

Each edge joins a crib letter to the ciphertext letter under it, labelled with its step in the message. Edges that lie on a loop are drawn in amber. Each loop is a test that a wrong rotor setting almost always fails. A red self-loop is a clash, which rules the position out before the Bombe even starts.

How can a machine test a loop without knowing the plugboard? It guesses, and follows the consequences. Take the letter with the most connections in the menu and suppose its plugboard partner is A. Every edge at that letter then forces a new connection. If the scrambler at step 23 turns A into K, the letter joined to it at step 23 must be plugged to K, and that conclusion spreads along the next edges in turn. Gordon Welchman’s diagonal board added one more rule: the plugboard swaps letters in pairs, so if T is plugged to K, then K is plugged to T.

A simplificationThis Bombe assumes the ring settings are known and models the rotors’ stepping exactly, which keeps false stops rare. The real machine ignored turnovers inside the crib, stopped more often, and left the ring settings to be worked out afterwards.

At a wrong rotor position the consequences spread until the test letter seems to be plugged to every letter at once, which is impossible, and the Bombe moves on. At the right position they stop short. The machine halts, and the one wire of the test register that stayed dark, or the only one that lit, names the real partner. The Bombe carried all 26 guesses on 26 wires at once, so one electrical test settled every guess for a position.

Fig. 13The Bombe at work
Scramblers, one for each menu edgeI · II · III
Test register · E
Wheel orders, left rotor down the side. Click one to run it alone.
no stopstopkey confirmedfalse stop
Stops
Each triple of drums is one scrambler, an Enigma without its plugboard, set to one step of the crib; its label names the menu edge it tests. For every rotor position all 16 scramblers move together, and the test register shows which partners of the test letter the implications allow. When all 26 wires light, the position is impossible. A stop is a position where a wire stays dark. Checking a stop reads off the plugboard and decrypts the message. The drum rims follow Bletchley’s colour code for rotors I to V: red, maroon, green, yellow and brown.

The real Bombe ran through all 17,576 rotor positions for one wheel order in about twenty minutes. By the end of the war more than two hundred of them were working in Britain, and the US Navy built more. Each stop was checked by hand on an Enigma replica, and when readable German came out, the day’s key was broken. Even then nobody had read the day’s traffic. Every message still had to be decoded on Typex machines, translated and assessed, as Fig. 22 shows.

III.6The fourth rotor

The German navy guarded its Enigma more closely than the army did. Its operators chose their three rotors from a box of eight rather than five. On 1 February 1942 the U-boats in the Atlantic switched to a new machine, the M4. Bletchley Park called the new U-boat key Shark, and for ten months it could read almost none of it.

The M4 made room for a fourth rotor by using a thinner reflector, and the fourth rotor was thin as well. It sits between the reflector and the left rotor, and it never turns while the operator types. It is set by hand to one of 26 positions before the message begins. There were two of these thin rotors, called Beta and, from July 1943, Gamma. Switch Fig. 7 to the M4 to see where it sits.

E = P−1 R−1 M−1 L−1 G−1 U′ G L M R P G is the fourth rotor and U′ the thin reflector
Backward compatibleBeta at position A with the thin reflector B is wired exactly like the old reflector B, so an M4 set that way could talk to three-rotor machines. You can check it in Fig. 7.

Mathematically, little changed. Group the middle terms and G−1U′G is itself a reflector. It swaps 13 pairs of letters and leaves none in place, because U′ does the same. So the M4 is still its own inverse, and it still never encrypts a letter to itself. In effect the fourth rotor offers 26 different reflectors to choose from, and that is all it does.

On paper the gain in key space was modest. Eight rotors instead of five, plus a fourth rotor with 26 positions, add about seven bits to the army machine’s 67, and the plugboard still dominates. The trouble for Bletchley was where those bits landed. The Bombe never searched the plugboard, because its loops dealt with the plugboard by logic. It searched rotor positions by brute force, and the fourth rotor multiplied exactly that search by 26.

Fig. 14Three rotors against four
Key space, in bits

Each extra bit doubles the number of settings. Gamma, added in 1943, doubled the M4’s once more.

Rotor positions the Bombe must try for one wheel order
Every wheel order, on a single Bombe
The bars show the key space of each machine in bits. The tiles show the part the Bombe had to search by brute force: each tile is one run through the 17,576 positions of three rotors, about twenty minutes of Bombe time. The M4 needs all 26 tiles for every wheel order, and with eight rotors there are 336 wheel orders. The bottom chart uses a linear scale, so the three-rotor bars are barely visible.

Bletchley got back in through captured paper rather than faster machinery. On 30 October 1942 sailors from HMS Petard boarded the sinking U-559 in the eastern Mediterranean and recovered its short-signal book and short weather cipher. Lieutenant Tony Fasson and Able Seaman Colin Grazier went down with the submarine. The documents gave cribs for the U-boats’ brief weather reports, and on 13 December 1942 Shark was read again.

The lasting answer was more Bombes, and faster ones built for four rotors. The US Navy’s high-speed four-rotor Bombes, designed by Joseph Desch at the National Cash Register Company in Dayton, Ohio, came into service in the summer of 1943 and carried much of the Shark work from then on. The fourth rotor never moves, so it added nothing to the period of the machine.

The lesson

The reflector made the Enigma convenient, and it guaranteed that no letter maps to itself. A guaranteed absence is information.

Lorenz

Teleprinter code, exclusive-or, and twelve wheels with 501 cams

The Enigma carried tactical traffic in Morse. For the highest level of command, between Berlin and the army groups, the German army used teleprinters that sent text automatically over radio. The Lorenz company built an attachment for them, the Schlüsselzusatz SZ40 and later SZ42, which encrypted the signal on the fly. Bletchley Park called all German teleprinter ciphers Fish, and this one Tunny.

IV.1Five holes per letter

Bletchley shorthandA hole was a cross (×) and no hole a dot (·). The control characters were written 9 for space, 3 and 4 for carriage return and line feed, + for figure shift, − for letter shift and / for the blank.

A teleprinter does not send letters as such. It sends the International Telegraph Alphabet No. 2, the Baudot–Murray code, in which every character is five binary pulses called impulses. On paper tape each impulse is a hole or no hole. Five bits give 32 codes: the 26 letters, and six control characters for space, carriage return, line feed, the shift to figures, the shift back to letters, and a blank.

Fig. 15The teleprinter alphabet
All 32 codes. Click one to add it to the tape.
Each column of the tape is one character, read top to bottom as impulses 1 to 5. The small holes between impulses 2 and 3 are the sprocket holes that pull the tape through the reader. The green characters are the six control codes, shown in Bletchley’s shorthand.

IV.2Adding a key, bit by bit

Lorenz encrypted with the rule Gilbert Vernam had devised for teleprinters in 1917. Each impulse of the message is combined with an impulse of key by exclusive-or, written ⊕. The result is 1 if exactly one of the two bits is 1. Exclusive-or is addition modulo 2, the binary version of Caesar’s addition modulo 26.

Z = P ⊕ KP = Z ⊕ K because K ⊕ K = 0: adding the key twice cancels it

Like the Enigma, the same operation encrypts and decrypts. That symmetry will matter again shortly.

Fig. 16Exclusive-or on tape
Exclusive-or
Column 1

Hover or tap a column of the tapes to see its arithmetic.

The key tape is random. Every hole in the key flips the corresponding impulse of the message. Adding the same key a second time flips the same impulses back, and the bottom tape is the plaintext again.

IV.3Twelve wheels

The key came from twelve wheels with cams around their rims. Each cam could be set raised or lowered, and the cam at the reading position gave one bit. Five χ (chi) wheels, one per impulse, had 41, 31, 29, 26 and 23 cams and stepped once per character. Five ψ (psi) wheels had 43, 47, 51, 53 and 59 cams and stepped together, but only when the two motor wheels allowed it. The μ61 motor wheel stepped every character and moved the μ37 wheel whenever its own cam was raised. The ψ wheels moved whenever μ37’s cam was raised.

K = χ ⊕ ψ′ ψ′ is the “extended” ψ stream, which repeats a character wherever the ψ wheels stood still

The sizes share no common factors, so the χ wheels alone come back to their starting positions only after 41 × 31 × 29 × 26 × 23 = 22,041,682 characters. With 501 cams to set, the machine seemed impossibly complex.

Fig. 17The key generator
Each step, all five χ wheels turn by one cam. The motor wheels decide whether the ψ wheels turn too; the dashed line lights up when they do. Each key impulse is the χ bit ⊕ the ψ bit in its column, and the key character is added to the plaintext character to make the ciphertext.

IV.4The depth

On 30 August 1941 an operator sent a message of about 4,000 characters from Athens to Vienna. The receiving operator asked for it again, and the sender repeated it with the same machine setting, which was forbidden. He also abbreviated as he retyped, so the two texts were not identical. SPRUCHNUMMER, message number, became SPRUCHNR.

Two messages sent with the same key are said to be in depth, and the key simply cancels.

Z1 ⊕ Z2 = (P1 ⊕ K) ⊕ (P2 ⊕ K) = P1 ⊕ P2

What is left is two plaintexts added together. Guess a word in one of them, add it at the right place, and the other message appears. John Tiltman worked through both texts this way and recovered almost 4,000 characters of key.

Fig. 18Two messages, one key
0

The top line is Z1 ⊕ Z2. The key is gone, but the two messages are still mixed together; the slashes at the start are where both texts agree. Slide a guessed word along it. Where the guess is right, the other message shows through as readable text. The bars score every position by how much the result looks like English, so the tall ones are worth a look.

IV.5Tutte’s rectangle

Tiltman’s key was a stream of 4,000 characters with no machine to explain it. Nobody at Bletchley had seen a Lorenz machine. Bill Tutte, a 24-year-old chemistry graduate recruited from Cambridge, took the first impulse of the key and wrote it out in rows, looking for a width at which the columns would repeat. It is Friedman’s column trick from Chapter II. At a width of 41 a pattern appeared.

The pattern was blurred, because the key is χ ⊕ ψ′ and the ψ wheels add noise. It becomes much clearer in the difference of the key, the sum of each character and the one before it, written Δ. Whenever the ψ wheels stand still, Δψ′ = 0, and the difference of the key equals the difference of the χ wheel.

ΔK = Δχ ⊕ Δψ′ ≈ Δχ ΔK(t) = K(t) ⊕ K(t − 1). The approximation holds whenever the ψ wheels stand still.

From patterns like this Tutte and his colleagues in the Research Section reconstructed the logical structure of the whole machine, all twelve wheels and the motor, by January 1942. It was one of the great intellectual feats of the war. The British did not see an actual Lorenz machine until 1945.

Fig. 19Finding the period
Width 37
37
Column agreement for every width

The first impulse of 4,000 characters of key, one mark per bit, written in rows of the chosen width. Solid marks are 1 and faint marks are 0; at wide rows the marks become narrow columns so the whole row still fits. At most widths the rectangle is noise. At 41, the χ1 wheel lines up down the columns. The pattern comes back at 82 and 123, twice and three times the period, because any multiple of a period is a period too; the first peak is the period itself. The chart scores each width by how strongly its columns agree; click a bar to jump to that width.

IV.6Colossus

Reading Tunny day to day meant finding the wheel settings of each message without the luxury of a depth. Tutte found a statistical way in. The difference trick works on the ciphertext too. For impulses 1 and 2,

ΔZ1 ⊕ ΔZ2 ⊕ Δχ1 ⊕ Δχ2 = ΔP1 ⊕ ΔP2 ⊕ Δψ′1 ⊕ Δψ′2

The right-hand side is 0 more often than 1. German teleprinter text is full of repeated characters, where ΔP = 0, and the ψ wheels often stand still, where Δψ′ = 0. So if you guess the starting positions of χ1 and χ2 correctly and count how often the left-hand side is 0, the count comes out noticeably above half. For a wrong guess it stays close to half. There are 41 × 31 = 1,271 guesses to test.

Dollis HillColossus was built at the Post Office Research Station in north London. Ten were working by the end of the war, and most were dismantled afterwards.

Counting that by hand was hopeless. Max Newman proposed a machine, and Tommy Flowers, an engineer at the Post Office, built one with about 1,600 valves. Colossus read the ciphertext from a loop of paper tape at 5,000 characters a second and counted electronically. It attacked its first message in February 1944. An improved Mark 2, with 2,400 valves, was running on 1 June 1944, days before D-Day.

Fig. 20Colossus at work
Ciphertext on a loop of tape · 10,000 characters
Count00000
    The typewriter: settings that beat the set total
    Colossus counts one setting per pass of the tape. Step 1 tries all 1,271 combinations of χ1 and χ2, and the map shades each by its count. Steps 2 to 4 set the other χ wheels against wheels already found, and the typewriter prints only the settings whose count beats the set total. Steps 5 and 6 were done by hand in the Testery; here statistics do them. The time shown is what a Colossus Mark 1 would need at two seconds per pass of the 10,000-character tape.

    With χ1 and χ2 set, the other three χ wheels needed only short runs of 29, 26 and 23 settings, each pairing the new wheel with one already found. Once all five were known, Colossus could strip them from the ciphertext. What remained is called the de-chi: the plaintext with only the ψ stream added.

    Set totalColossus did not print every count. The operator chose a threshold, the set total, and the typewriter recorded only the settings that beat it.

    The de-chi went to the Testery, Major Ralph Tester’s section, where the motor and ψ settings were found by hand, and a British-built Tunny machine set to all twelve wheels printed the German. Colossus itself never produced a line of plaintext. The simulation does that part with statistics instead. Wherever the motor holds the ψ wheels still, a doubled letter in the plaintext shows up as a doubled letter in the de-chi, and that finds the motor. Then each ψ wheel in turn is set to the position that makes the text read most like German.

    The lesson

    The Lorenz key looked random, but its wheels stood still in step with one another, and differences made that visible.

    What broke them

    Every cipher on this page stretched a short secret into a long key

    Each of these ciphers turned a small secret into a long key, and each stretch left structure behind. Caesar used one shift for the whole message. Bellaso’s keyword repeats. The Enigma’s rotors cycle, its plugboard never moves, and its reflector forbids a letter from becoming itself. The Lorenz wheels are periodic and their ψ wheels pause together. Every break on this page found that structure and measured it.

    Fig. 21How long before the key repeats
    CipherStructure left behindHow it was exploited
    CaesarOne fixed alphabetFrequency analysis (Fig. 2)
    VigenèreThe keyword repeatsKasiski and Friedman split the text into columns (Fig. 5)
    EnigmaNo letter encrypts to itself; the plugboard never movesCribs, menus and the Bombe, rebuilt for four rotors (Figs. 11–14)
    LorenzPeriodic wheels; ψ wheels stand still together; a key sent twiceTiltman’s depth, Tutte’s differences and Colossus (Figs. 18–20)
    One-time padNone, if the pad is random and used onceOnly broken when pads were reused, as in Venona
    The period of the key on a logarithmic scale: each gridline is ten times the one before. A longer period made a cipher stronger, but none of these machines was broken by waiting for its key to repeat.

    The machines were rarely the weakest part. The breaks came from operators who repeated message keys, sent the same text twice, or began every report with the same words. Auguste Kerckhoffs had warned in 1883 that a cipher system must stay secure even if the enemy knows everything about it except the key. Enigma and Lorenz were built on the hope that the machines themselves would stay secret, and in the end the enemy knew everything about them.

    V.1No machine read a message

    It is tempting to picture the Bombe or Colossus printing out German orders. Neither did. The Bombe produced a few candidate rotor settings, Colossus a few wheel positions. Before and after them stood thousands of people: intercept operators copying Morse through the night, analysts sorting the traffic, codebreakers finding cribs, Wrens running the machines, typists, translators and intelligence officers. By 1945 nearly 10,000 people worked at Bletchley Park and its outstations, about three-quarters of them women.

    Y-stationsThe British called wireless interception “Y”, probably from the initials WI. The intercept stations were Y-stations, run by the armed services, the Foreign Office and the Post Office.

    Follow a message through either lane below. The machines on this page sit in the amber stages. Everything else was done by hand, and every stage passed a different product to the next.

    Fig. 22From the air to the commander
    peoplemachinesimulated on this page
    Each lane follows one intercepted message from the radio to a commander. Amber stages were done by machines, everything else by people. The Bombe and Colossus each delivered a few numbers, never a message. Select a stage to see who did it and what it handed on, or follow a message through both lanes.

    Bletchley Park’s work remained secret until the 1970s. Most of the Colossi were broken up after the war, and Tutte’s reconstruction of the Lorenz machine was publicly recognised only decades later.

    Keys in the open

    Everything above was symmetric. How two strangers share a key today

    Every cipher on this page is symmetric: the same secret sits at both ends of the line. It was Caesar’s shift, Bellaso’s keyword, the Enigma’s daily key sheet, the settings of the Lorenz wheels, the one-time pad. Symmetric ciphers can be very strong, and today’s are. Their weak point was the key itself, which had to be printed, carried and guarded, and could be captured, as U-559’s codebooks were.

    GCHQ got there firstJames Ellis, Clifford Cocks and Malcolm Williamson at GCHQ, Bletchley Park’s successor, found the same ideas between 1970 and 1974. Their work stayed secret until 1997.

    In 1976 Whitfield Diffie and Martin Hellman showed how two people can agree a secret key while an eavesdropper hears every word they exchange. The idea rests on the clock arithmetic of Chapter I. Raising a number to a power modulo a prime is quick. Going backwards, finding the power from the result, is called the discrete logarithm, and for large primes nobody knows a fast way to do it.

    A = ga mod pB = gb mod p Ba = Ab = gab mod p p and g are public; a stays with Alice and b with Bob
    Fig. 23Agreeing a key in public
    plainkeycipher

    Move Alice’s and Bob’s secret numbers. Only the values in the middle column ever travel over the line, yet both ends arrive at the same shared key, shown in green with a matching colour swatch. Eve sees the whole middle column. With a small prime she can try every power until one matches, so pick a larger prime and watch her work grow. Below, the shared key seeds a key stream that is added to the message letter by letter, the symmetric half of the job.

    Diffie–Hellman agrees a key but cannot tell you who is on the other end. Public-key encryption and signatures add that. In 1977 Ron Rivest, Adi Shamir and Leonard Adleman published RSA, in which each person has two keys. The public key works like an open padlock that anyone can snap shut, and only the matching private key opens it again. Multiplying two large primes is easy. Recovering them from their product is the hard problem that keeps the private key private.

    c = ke mod nk = cd mod n n = p · q is public with e; d, with e · d ≡ 1 mod (p − 1)(q − 1), is the private key
    Fig. 24A padlock anyone can close
    Bob makes a key pair from two secret primes and publishes only the padlock, the pair (n, e). Alice uses it to lock a session key for the symmetric cipher and sends the result over the open line. Only Bob’s private key d unlocks it. Eve can try to factor n back into Bob’s primes. That is quick for these small numbers and hopeless for real ones.

    Public-key arithmetic is slow, so it is used only to agree or carry a key. The message itself goes through a fast symmetric cipher. When your browser opens a page over https, it runs an elliptic-curve version of Diffie–Hellman with the server, checks the server’s signature against a certificate, and then encrypts everything with AES or ChaCha20 under the fresh shared key. Every session gets a new key, so there are no depths to exploit, and every part of the design is public, as Kerckhoffs asked.

    After quantum computersA large quantum computer could undo both the discrete logarithm and factoring. Browsers have begun to mix in post-quantum key exchange such as ML-KEM, standardised in 2024.

    Real keys are far larger than the ones in these figures. Diffie–Hellman primes run to more than 600 digits, or elliptic curves give the same strength with shorter numbers, and RSA moduli have 617 digits or more. The best known attacks on them would need something like 2112 to 2128 operations, which no computer on Earth can do.

    The lesson

    Public-key methods carry the key. Symmetric ciphers, the descendants of every machine on this page, carry the message.