DSP Explorables
Enigma
Old ciphers fell because they used the same substitution, or a few in turn, over and over, and letter counts gave them away. The obvious fix is a different substitution for every letter, and in the 1920s machines made that practical. The most famous is Enigma, patented by the German engineer Arthur Scherbius in 1918 and adopted by the German armed forces in the late 1920s. It enciphered their messages through the Second World War, and it was broken: first in Poland, then at Bletchley Park in England. This page builds the army’s machine, the Enigma I, and then breaks it the way they did.
1 · The machine
Section titled “1 · The machine”An Enigma looks like a typewriter in a wooden box. Press a key and, instead of printing, a lamp lights under a second set of letters: the enciphered letter. Inside, the key press is a current that runs through a chain of wiring and back:
- the plugboard, which swaps pairs of letters with cables (up to thirteen pairs; ten was usual);
- three rotors, each a wheel with 26 contacts on each face, cross-wired inside: each rotor is a fixed substitution, but it can turn, so which contacts line up changes;
- the reflector, which wires the contacts together in 13 pairs and sends the current back;
- back through the three rotors, by a different route, and the plugboard again, to a lamp.
The army’s machines came with five rotors, numbered I to V, each wired differently; the day’s key said which three to use, in which order. Their wirings, and the reflector’s, are known today, and this machine uses them.
The Enigma I with rotors I, II and III and reflector B, all wired as the real ones were. Choose the rotors and their start positions, plug some pairs if you like (“AB” swaps A and B), then press keys (click them, or type while the keyboard has the focus). The path of the last key press is drawn: in through the plugboard and rotors to the reflector (orange), and back out by another route to the lamp (blue). With rotors I, II and III starting at AAA and no plugs, typing AAAAA lights BDZGO, the check every Enigma simulator is held to (pinned in the tests). The same key five times gives five different letters: the rotors moved between presses.
2 · Stepping
Section titled “2 · Stepping”The rotors are what make Enigma more than one big substitution. Before each letter is enciphered, the right rotor turns one place, so the next letter goes through different wiring. Like the digits of a mileage counter, each rotor has a notch that, at one point in its turn, moves the rotor to its left on by one too: rotor III’s notch is at V, so when it moves on from V, the middle rotor steps.
There’s a quirk. The middle rotor’s own notch also catches the middle rotor itself: when the middle rotor reaches its notch, the next key press moves it and the left rotor. So the middle rotor moves twice in two key presses, the double step. It cuts the machine’s period a little (16,900 letters before the rotors repeat, not 17,576), but more importantly it’s part of the machine, and a simulator that leaves it out gets the wrong letters.
Rotors I, II and III, as the machine’s windows show them. Press a key and watch which rotors move (the right in blue, the middle in orange, the left in purple). From ADU: the right rotor moves to V, its notch; the next press carries into the middle, ADV → AEW; and E is the middle rotor’s notch, so the next press moves the middle and the left: AEW → BFX. That sequence, ADU, ADV, AEW, BFX, is pinned in the tests.
3 · Two properties, one cause
Section titled “3 · Two properties, one cause”The reflector, sending the current back through the machine by another path, has two consequences.
The same settings decrypt. At any one position, the machine is a set of swaps: if A goes to G, then G goes to A, because the current from G retraces the path from A backwards. So the receiver sets the same start position, types the ciphertext, and reads the message off the lamps. There’s no separate decrypting mode.
A letter never becomes itself. A pressed key’s own wire carries the current in; the reflector can’t send it back on the same contact, so it always arrives at a different lamp. That sounds harmless, even a feature. It was the most useful flaw the codebreakers had, as section 5 shows.
Rotors I, II and III with three plugged pairs (AQ, BJ, CM). Encipher the message, then put the ciphertext through from the same start: the message comes back. Below, the whole machine at the first letter’s position, as the 13 swaps it is (a different 13 at every position). No letter is ever swapped with itself, so the count of letters enciphered as themselves is always 0: the tests check it for 200 random settings, rings and plugs included.
4 · How many keys?
Section titled “4 · How many keys?”The daily key set out the rotor order, the ring settings (where each rotor’s wiring sits against its lettered ring), the plugboard and the start position. Counting, for the Enigma I with ten plugged pairs:
| Choice | Ways |
|---|---|
| Three rotors from five, in order | 5 × 4 × 3 = 60 |
| Start positions | 26 × 26 × 26 = 17,576 |
| Ring settings that make a difference (the left rotor’s only repeats its start position’s work) | 26 × 26 = 676 |
| Ten pairs of plugs among 26 letters | 26! / (6! × 10! × 2¹⁰) = 150,738,274,937,250 |
The plugboard is the giant: there are 26! orders of the letters, but within each pair the order doesn’t matter (2¹⁰), nor does the order of the ten pairs (10!), nor of the six letters left unplugged (6!). Oddly, ten pairs isn’t the most: eleven give 205,552,193,096,250.
Multiplied out, that’s 107,458,687,327,250,619,360,000 keys, about 1.1 × 10²³, between 2⁷⁶ and 2⁷⁷: a 76-bit key, in today’s terms. (The figure often quoted, 158,962,555,217,826,360,000, leaves out the rings.) Trying them all was out of the question then, as it would be hard even now. Enigma was broken anyway, because no one tried them all: they used what they knew about the messages to throw away almost all the keys at once.
5 · Cribs
Section titled “5 · Cribs”The codebreakers rarely knew a message, but they often knew a phrase in it. Military messages are routine: a weather station reported in the same format every day; units reported “nothing special to report” (keine besonderen Ereignisse); messages began with addresses and titles. A guessed phrase like this is a crib, the same idea as on the one-time pad page.
The difficulty is knowing where in the message it goes. Here Enigma’s flaw from section 3 helps: no letter enciphers to itself, so the crib can’t go anywhere that one of its letters sits over the same letter of ciphertext.
An intercepted message of 68 letters, and the crib WETTERVORHERSAGE (“weather forecast”) slid along it. Wherever a crib letter falls on the same ciphertext letter (red), the crib can’t be there. Below, every position: the possible ones filled. The crib fits 24 of the 53 places; the true one (26) is among them. More than half are ruled out without knowing anything about the key.
6 · Finding the settings: the bombe
Section titled “6 · Finding the settings: the bombe”With a crib in place, each of its letters is a test of the machine’s settings: at position 26 the machine must turn W into this ciphertext letter, at 27 E into the next, and so on. Try a setting, encipher the crib, and at the first letter that comes out wrong, throw the setting away. Most settings fail on the first or second letter, so testing them is quick, and that’s exactly what a machine can do over and over.
intercepted:
A simplified bombe, run in your browser. It tries every rotor order and every start position (60 × 17,576 = 1,054,560 settings) with the rings at A and no plugboard, keeping the settings under which the crib, at the given position, enciphers to the intercepted letters. To keep it simple, this message was enciphered without the plugboard. With the crib at 26, exactly one setting fits, the true one (pinned in the tests), and it deciphers the whole message. Move the crib to another position and none fits.
The real problem was harder: the plugboard was always in use, and it changed the letters going in and coming out of the rotors, so a crib’s letters couldn’t be tested directly. The British bombe, designed by Alan Turing, with an improvement by Gordon Welchman, got round it with the crib’s menu: draw each letter of the crib and the ciphertext letter under it, and join them, labelled with the position.
The menu for WETTERVORHERSAGE at position 26 of the message above: each line joins a crib letter to the ciphertext letter it became, labelled with its position. Some lines close into loops, like E to I (at 27), I to S (at 38) and S back to E (at 41). Step through the loops: this menu has seven.
A loop is what defeats the plugboard. Suppose E is plugged to some unknown letter, x. At position 27 the rotors must turn x into whatever I is plugged to; at 38 that must become S’s partner; at 41 that must come back to x. Whatever the plugboard is, the loop has to close. So the bombe, for each rotor setting, assumed a partner for E, followed it around every loop in the menu, and if it didn’t come back to itself, that setting was wrong, plugs and all. Welchman’s diagonal board added the plugboard’s own symmetry (if E is plugged to x, x is plugged to E), which made each test far stronger. A bombe was dozens of Enigma rotor sets, spun electrically through every position. The settings that survived were tried by hand on the message.
7 · Who broke it
Section titled “7 · Who broke it”Enigma was first broken in Poland. In late 1932 Marian Rejewski, a mathematician at the Polish Cipher Bureau, worked out the wiring of the army’s rotors, using the mathematics of permutations together with documents that French intelligence had obtained from a German source. With Jerzy Różycki and Henryk Zygalski he went on to read Enigma messages for much of the 1930s, inventing the methods and machines (including the bomba) that kept up as the Germans changed their procedures. In July 1939, weeks before the invasion of Poland, they shared everything with British and French intelligence, including reconstructed machines.
At Bletchley Park that work became an industry: the bombes, thousands of staff, and the habits of German operators (stereotyped messages, predictable keys) as a constant supply of cribs. The lessons are the ones from What we want from cryptography: the enemy will learn the machine (Kerckhoffs’s principle), so everything rests on the key; and a cipher that leaks anything at all about its message (here, that no letter is itself) will have that leak used against it.
Summary
Section titled “Summary”- Enigma is a different substitution for every letter: a plugboard, three stepping rotors and a reflector.
- The rotors step before every letter, with notches carrying (and the middle rotor’s double step).
- The reflector makes each position a set of 13 swaps: the same settings decrypt, and no letter ever enciphers to itself.
- About 10²³ keys, most of them from the plugboard: too many to try.
- Cribs guessed from routine messages, placed where no letter maps to itself, test the settings letter by letter; loops in the crib’s menu test them whatever the plugboard is. That’s what the bombes did.
Further reading
Section titled “Further reading”- Marian Rejewski, “How Polish Mathematicians Deciphered the Enigma”, Annals of the History of Computing (1981): the first break, in his own words.
- Gordon Welchman, The Hut Six Story (1982): Bletchley Park, the bombe and the diagonal board, from the inside.
- Simon Singh, The Code Book (1999): an approachable account of Enigma and its breaking, among much else.