Decoding the Enigma Machine
After visiting Bletchley Park, David Freeborn built his own virtual Enigma and Bombe machines: here's how they work
Whilst marking student papers on a quiet Thursday evening, I found myself mulling over the many parallels between the lives of a university lecturer and a secret intelligence operative. Both careers are glamorous, sexy and dangerous in equal measures. But the connections run deeper than these superficial similarities. From Sir Francis Walsingham, to the Cold War atomic spies, to the contemporary AI espionage, intelligence operatives have needed experts with skills in fields like mathematics, linguistics, and more recently computer science.
I recently had the chance to visit Bletchley Park with the Computational Philosophy Lab, and to explore one of the most intense episodes in the history of academia, intelligence, and war. Bletchley Park was a secret wartime research institute, filled with mathematicians, linguists, classicists, chess players, crossword solvers, engineers, clerks, operators, and analysts. It brought together figures such as Alan Turing, Gordon Welchman, Dilly Knox, and many others, and turned their collective ingenuity toward the problem of reading encrypted German messages.
Two machines sit at the centre of that story. The first is the Enigma machine, used by the German military to encipher messages. The second is the Bombe, built at Bletchley Park to help break Enigma traffic, developed from the earlier Polish Bomba machine. Enigma was a portable electromechanical cipher machine. The Bombe was a specialised machine for testing possible Enigma settings against a guessed fragment of text.
I do not have the resources, workshop, or mechanical competence to build a real Enigma machine, still less a working Bombe. So instead, I coded virtual versions of the machines. I’ve turned them into an interactive visual interface which you can try out here.
Feel free to experiment with these virtual machines. Change the rotors, move the starting windows, add plugboard cables, encode a message, then try to break it. But before doing that, it helps to understand what the machines were actually doing.
The Enigma Machine

The Enigma machine was used to encode secret messages. It takes a mechanical keyboard as its input, and a lampboard (which lights up specific letters) as its output. The core of the machine is essentially an electrical path that changes every time a key is pressed. The operator presses a letter on the keyboard, an electrical signal travels through a sequence of components, and one bulb lights up on the lampboard. That bulb is the encrypted letter.
For example, suppose that the next letter in our original secret message is an A. The operator presses A and perhaps the Q bulb lights up, so the operator should write down Q as the next letter in their encoded message.
The machine did not handle spaces, punctuation, or ordinary printed text. It only worked with letters. Before encryption, a message had to be turned into a stream of letters. So a phrase like:
WEATHER REPORT AT DAWN
would first become something like:
WEATHERREPORTATDAWN
Next, the message will get encoded. The first stage is the plugboard, which implements one of the simplest forms of coding possible: it simply swaps letters. In essence, the plugboard consists of a panel of sockets with cables between pairs of letters.
These cables are used to switch letters: for instance, if A is plugged to V, then A becomes V and V becomes A. The cable has no direction. If a letter has no cable attached, it passes through unchanged.
With 26 letters, each plugboard cable connects two letters, so at most 13 cables could be used. But only ten cables were used! Why? Using all 13 cables is not actually the combinatorial maximum. If every letter is plugged, there is no choice about which letters are left unplugged. With ten cables, by contrast, the operator chooses 20 letters to plug, leaves six letters unplugged, and then pairs the 20 selected letters into ten unordered pairs. In fact, exactly eleven cables gives the largest number of possible plugboard patterns, but ten is very close and was the standard wartime practical choice, giving some 150,738,274,937,250 possibilities.
For the mathematically inclined, we have 26 letters and let there be k cables. Then each cable uses two letters so there are 26C2k choices of which letters are plugged. Then we need to choose how to pair up those plugged letters. There are (2k)! ways to do this, but the order within each pair doesn’t matter, so we must divide this by 2k. But the order of the pairs also doesn’t matter, so we must divide by a further factor of k!. So the total formula for the number of combinations is:

A with an N, and any case of the letter N with an A, and so forth.After the plugboard, the signal enters the rotors. These were physical wheels, which could be swapped in or out of the machine. Each individual rotor gives a fixed scrambling of the alphabet. For example, a rotor might wire A to E, B to K, C to M, and so on.
But the rotors can turn, so the same internal wiring presents a different face to the incoming signal depending on its position. This is one of the tricks that makes Enigma more sophisticated than a simple substitution cipher. The substitution changes as the rotors move. If we press A five times in a row, we will (generally) get a different letter each time.

The right-most rotor turns one step with each new keypress. Each rotor has a notch, and when a rotor reaches its notch it causes the rotor to its left to move one step. So we might expect the second rotor to turn once every 26 keypresses. And the third rotor to turn once after every 262 = 676 keypresses. Think of the second, minute and hour hands of a clock, but base 26 instead of base 60.
But there’s an additional complication here! Because of the way the ratchets and notches interact, the middle rotor can step on two consecutive keypresses. This is called the double-step. It is a small mechanical quirk, but it affects the exact sequence of substitutions the machine produces.
The operator can make a number of choices when setting the rotors. First, they choose which rotor wheels to use and where to place them. In the standard German Army and Air Force three-rotor Enigma, after rotors IV and V were added, there were five rotors available, labelled I, II, III, IV, and V. The operator chose three of these and placed them in left, middle, and right positions. Then they choose the window setting, which determines the starting position of each rotor.
The operator sees the rotor positions through three small windows. These are the window letters. If the windows show:
M C K
then the left, middle, and right rotors are currently at positions M, C, and K.
Then, there is one more rotor-related setting: the ring setting. This is easy to mix up with the window position. The window position tells you how the rotor is currently turned. The ring setting tells you how the alphabet ring is aligned with the rotor’s internal wiring. Put differently: the rotor has a wired core and an outer alphabet scale. The ring setting changes how those are lined up. Two machines can show the same window letters but behave differently if their ring settings differ.
After passing through the rotors, the electrical signal reaches the reflector. The reflector is a fixed wiring unit at the far end of the machine, which substitutes each letter with another (similar to the plugboard). Unlike the plugboard, it could not be rewired, but sometimes whole reflectors could be swapped out for other choices. In the later war period, the German army used two main reflectors, Umkehrwalze B and Umkehrwalze C.

AAA, and rotor configuration MCK. The plugboard has also been wired.Crucially, the reflector then sends the electrical signal back through the rotors in the opposite direction. The signal then passes through the plugboard once more. Finally, the output encoded signal lights up at the lampboard, and the operator writes it down. So the entire journey of one letter in our message could look like this.

N. The plugboard switches each N to an I. Then the rotors, in their current configuration switch the I to an S, the S to a V and the V to an E. The reflector switches each E to a Q. Then the Q passes back through the rotors, in the same configuration, and through the plugboard. In this case, our encoded message records a T.Putting these settings together gives a sense of why Enigma was such a formidable machine. Start with the plugboard: we’ve already seen that this gives 150,738,274,937,250 possibilities. Then there are the five possible rotors, with three possible slots. This gives a further factor of 5 x 4 x 3 = 60 combinations. Furthermore, each rotor can take one of 26 initial starting positions giving a further 263 = 17,576 combinations. So this alone gives:
or 159 quintillion combinations. In fact, this is something of an underestimate because we could also vary the 17,576 ring settings as well. This is what experts call “a big number”.
The Bombe

So how on earth did the team at Bletchley Park decode the Enigma’s messages? The short answer is, with great difficulty. There were far too many Enigma combinations to systematically try out through every possible setting. Even with contemporary cryptographic methods and computers, the task would be very challenging: in a modern study, a short 72-letter genuine message was broken in around five days on a four-core PC. This would have been too slow for wartime period, when the German army and navy were changing their Enigma settings every twenty four hours.
Instead, the Bletchley Park decoders had to make a guess about what part of the message might say. These messages were called “cribs”. The crib might be something routine and predictable: a weather report, a standard military formula, a repeated heading, a place name, or a phrase that operators were known to use. Codebreaking often begins with the hope that someone has said something boring. Fortunately, the wartime encoded messages frequently used a number of standard phrases, such as Wettervorhersage (“weather forecast”) or Heil Hitler.
The first problem is that we may not know where the guessed phrase appears. So we slide it along the encrypted message and compare the letters position by position. If the guessed original letter and the encrypted letter are ever the same in the same position, that placement is impossible. Enigma could not encrypt a letter as itself. So if our guess puts an A underneath an encrypted A, we can immediately reject that alignment.
For a surviving alignment, each position gives us a small test. Suppose that, at one point, our guessed message has W and the encrypted message has N. Then, if the guess is right, Enigma must have changed W into N on that particular keypress. At the next keypress, perhaps E must have become D. A longer crib gives a whole list of these required letter changes.
The Bombe turned that list into a “menu” of possible letter changes demanded by the crib. The Bombe then tests settings against that menu. Suppose that, in one position, our guessed message has W and the encrypted message has N. The menu draws a line between W and N for that position. The line means: if our guess is right, then on that keypress Enigma changed W into N. This records the result that the whole machine must produce at that moment.
Luckily, the same letters tend to appear more than once in a crib. Suppose one part of the guessed phrase relates W to N, another relates N to E, and another relates E back to W. Then these requirements are no longer isolated facts. They form a connected pattern. The more connected it is, the more tightly it helps us to select for candidate machine settings.
The Bombe then tries possible Enigma settings against this menu. A candidate setting means a particular choice of rotor order, reflector, ring settings, and starting window letters. Once those choices are fixed, the rotor part of the machine is no longer mysterious. We can calculate what the rotors would do at the first crib letter, then after one step, then after two steps, and so on.
The big unknown is the plugboard. The Bombe asks: could there be any plugboard wiring that makes all these letter requirements true at once?
This is where contradiction does the work. Imagine testing a candidate setting. One chain of requirements might force the conclusion that A must be plugged to F. Another chain, using the same candidate rotor setting, might force the conclusion that A must be plugged to Q. That cannot happen. A plugboard socket can have only one cable. A cannot be plugged to both F and Q. So this candidate setting is crossed out.
The best menus had “loops”. A loop occurs when the chain of letter requirements eventually comes back to a letter it has already used. Loops are powerful because they make the test self-checking. If we follow the consequences of a candidate setting around the loop and come back with an impossible plugboard demand, then this candidate setting can be considered dead.
Gordon Welchman’s diagonal board improved this process dramatically. Welchman was one of the key Bletchley Park mathematicians working on the Bombe. His diagonal board built one simple fact about the plugboard directly into the machine: a plugboard cable has no direction. If A is connected to V, then V is connected to A.
That sounds obvious, but it made a big difference. Suppose one part of the test suggests A is connected to V. The diagonal board immediately lets the machine also use the reverse fact, that V is connected to A. This allows information from one part of the menu to feed into other parts that mention V, and then from those into still more parts of the menu. The test becomes much more tightly connected. Contradictions that might otherwise remain hidden can appear quickly.
When the Bombe finds a candidate setting that does not produce a contradiction, it stops. Each of the surviving “stops” then had to be checked. The codebreakers would try to complete the remaining plugboard wiring and see whether the message began to turn into readable German.
Decoding a Secret Message
So now you know everything you need to build Enigma, to build a Bombe, and to decode your enemies’ messages.
But if your garage supplies of spring-loaded pins and Bakelite rotors are running low, I encourage you to try my Enigma and Bombe app. In the Enigma tab, you can choose a wartime-style configuration and encode a message of your own. In the Bombe tab, you can try to recover a message from an encrypted text and a crib. Be warned: without a good crib, this will be painfully slow.
If you’d like to try for yourself, here’s a message you could try to decode:
IXFPIMSHJFKPCACAUECNRQXRRKCOKUYVRNUHSETMKCOZVXKAWSFOFGNPDJAVDTYPIVFWHDMXXUCOZBVLIWJLTRBXVKQDSWKVGCFHQWBTNYOIFIJLASQSTBBIJPRARQSNRHGOQCLYVPUBHKQVJNTL
I can reveal that we used ring setting FFF to encode the message, and a suitable crib could be: WECANONLYSEEASHORTDISTANCEAHEAD.
It might take the code version of the Bombe a while to find the full list of stops, so I would put the kettle on while you wait. I expect that only one stop will survive, so if you check the completions, this should give you the answer. The first person to email me1 with the correctly decoded message will earn a prize.
david [dot] freeborn [at] nulondon [dot] ac [dot] uk


