To many, the Enigma machine is an enigma. But it’s really quite simple. The following is a step-by-step explanation of how it works, from the basics to the full machine.
Possibly the greatest dedicated cipher machine in human history the Enigma machine is a typewriter-sized machine, with keyboard included, that the Germans used to encrypt and decrypt messages during World War II. It’s also one of the machines that the Polish Cipher Bureau and those at Britain’s Bletchley Park figured out how to decipher, or break. Most recently the story of how it was broken was the topic of the movie The Imitation Game.
Let’s start with the basics.
A Simple Substitution Cipher
Most have seen how to encrypt messages using a simple cipher like this.
Let’s say we want to encrypt the word
Hackaday. This is called the plaintext message. We’ll treat all letters as uppercase. Using the above cipher we look in the top line for the
H and we substitute the letter below it, a
Z. Similarly, looking for the
A in the top line, we see we should substitute it with a
G. The encrypted text becomes
ZGTBGNGV. This is called the ciphertext. To decrypt it we do the reverse, look for each letter in the bottom row and substitute with the corresponding letter in the top row, getting
That’s the very basics. Let’s take this further like the Enigma machine does.
We could redraw the cipher as two alphabets with letters in alphabetical order, and draw lines between the paired letters. The effect is the same in this case. But those lines can be wires, electrically connecting each pair, which opens up the possibility of easily changing how the substitution is mapped through to the ciphertext.
The ability to change the mapping is important because once someone deduces that
G is the substitution for
A, they’ll know that’s true for every
G in the ciphertext. An improvement would be for all those pairings to change. And even better, if they change each time a letter is encoded.
One way to easily implement that, and it’s the way it’s done in the Enigma, is to embed all that wiring in a wheel/rotor. By turning the rotor while leaving the letters stationary, the connections between letters change. After one turn,
A would now be substituted with whatever
Z formerly was, namely
J. Repeating this step of substitution followed by turning the rotor for each letter,
ZJGZLVFA. Follow the diagram above and you notice that the first
Z came from the
H, but the
Z in the fourth position came from the
In the rotor, each wire has external contact points on either end. That allows some multiple of these rotors to be put side-by-side, with adjacent contacts touching. And internally, each of the rotors are wired differently i.e. each rotor contains a different cipher. In some Enigma machines there were three rotors, and the most used was eight. As shown in the photo from inside an actual Enigma, each rotor also has an attached alphabet ring that turns with the rotor and is used to set the initial position of the rotor.
How many possible paths does that give us through three rotors for the letter
A? Keep in mind that each rotor can be turned to any position. That means that for the first rotor there are 26 possible paths through it for
A. But once we’ve followed the wire through the first rotor, there are now 26 possible paths through the second rotor. And then 26 more possible paths through the third one. The total possible number of paths for
A to take through all three rotors is therefore 17,576.
26 x 26 x 26 = 17,576
As we said, each rotor is wired differently. They’re therefore given names using Roman numerals: I, II and III. But to further complicate things for anyone who might have such a machine and be trying to decrypt a message, the rotors are allowed to be moved around before use. Rotor II might be the left one, with rotor III in the middle and rotor I on the right. And to add even more possibilities, up to eight rotors were made altogether, each with their own wiring and Roman numerals: IV, V, VI, VII and VIII. The German Army and Air Force used five and the Navy used up to eight. Prior to use, for a three-rotor machine, three rotors would be selected from however many rotors were available to choose from.
Assuming we were trying to decrypt an army message, we’d have a choice out of five rotors to use for the left one, then a choice out of the four remaining rotors to use for the middle one, and then a choice out of three for the right one. That gives 60 possible ways to choose the three rotors being used for a message.
5 x 4 x 3 = 60
And since there were 17,576 possible paths a letter could take through the rotor, that gives 1,054,560 possibilities altogether.
17,576 x 60 = 1,054,560
Enigma Machines With Only Rotors
To make the Enigma easy to use, a circuit including a battery, keyboard, and light-up letters for a display were added. Shown in the illustration are just a few of the keys and lit letters, and only a few of the wires in the rotors.
One side of the battery is connected to all the lights for lighting up some letters. When the ‘A’ key is pressed, the key’s switch makes a connection with the other side of the battery. The other end of the switch goes up to connect to the entry wheel which makes electrical contact with one of the contacts on the first rotor. From there the circuit continues through the other two rotors, following the wire paths within those rotors. At the opposite end of the rotor is something called the reflector which causes the circuit to follow paths back through the rotors until it emerges back at one of contacts of the entry wheel. From there the circuit goes to the
F key. Since the
F key was not pressed, electrical contact is still made with the
F light, completing the circuit with the battery and lighting it up. The lit
F means that the key that was pressed,
A, should be substituted with the letter
F. The operator or someone else writes this down.
One mechanism not illustrated here is the one that causes one or more of the rotors to turn as a result of the keypress, called the turnover. The first wheel would turn one letter position for each keypress, as illustrated above with the ciphers. On some versions of the machine, the second rotor turns one position only after the first rotor has made a complete rotation. The third rotor then turns one position for every complete rotation of the second rotor. But all that varied from version to version, some rotors turning twice for each rotation of the one to the right of it.
Adding A Plug Board
In 1930, German army versions added a plugboard, or steckerbrett. This allows letters to be swapped. In the circuit shown,
F are swapped. When the
A is pressed, as we saw above without the plugboard, the output would be
F. But with the plugboard it’s
D. If instead we’d swapped
A, then the swap would have affected the circuit before going to the rotors and the rotors would have started with
D. Following that wiring, the output would have been
Since there are 26 letters, up to 13 swaps could be done but typically only 10 were. The mathematics for figuring out the number of possible ways to connect the plugboard is a little complicated but the number is 150,738,274,937,250. Multiplying that by the other possible combinations we gave above, we get that the overall number of possible paths a letter can take to be substituted is 158,962,555,217,826,360,000.
There were a few flaws with the way operators would use the machine, mostly failing to follow procedures. But in terms of flaws in the design of the machine, the main one had to do with the reflector.
The reflector makes the Enigma self-reciprocal. That means that, given the same starting conditions, the machine can both encrypt and decrypt. To use the example above with the plugboard, when you press
D lights up, but press
D and the
A lights up. This meant that, ignoring the plugboard, a letter would never substitute itself. This fact helped codebreakers break the Enigma.
We’ve already mentioned a few variations above, such as the number of rotors, the presence of the plugboard, and the point at which rotors turn.
Another variation among different versions of machines was in the way the keyboard was connected to the entry wheel. In commercial machines they were connected as per the QWERTZ keyboard: Q-A, W-B, E-C, and so on. In military machines they were connected alphabetically: A-A, B-B, and so on.
In some versions, the reflector could also be rotated, in some cases only once before use and in other cases, automatically.
We’ve talked about setting the initial positions of the rotors. To do this, the rotors have an alphabet ring attached to them and they’d set a rotor by turning it until a desired letter appeared in a small window. However, in later versions of the machine, the alphabet ring itself could be turned separately from the wired rotor. This meant there were two things to set initially for the rotor, the alphabet ring, called the ring setting, and then the whole rotor.
Using The Enigma
With so many versions of the Enigma machine, there were plenty of different possible settings to configure before using it. Typically, both the people encrypting a message and the descryptors would have a list of settings, sometimes different ones for each day.
Some of the columns in the sample settings given here are:
- Wheel order (Walzenlage): which rotors to put in the machine. Remember, each rotor is named using a Roman numeral,
- Ring settings (Ringstellung): position of the alphabet rings with respect to the wired rotors for versions that had alphabet rings,
- Plug connections (Steckerverbindungen): which letters swap with which other letters,
The person doing the encrypting would choose random rotor positions themselves and include them at the start of the messages. During the latter part of world War II, the procedure for doing so was as follows. He’d first make up an initial start position, for example, ABC, and a message key, DEF. He’d set the rotors to ABC and type in DEF. Let’s say that encrypts to GHI. Next he’d set the rotors to the message key, DEF, and start typing the plaintext message. He’d record the output, which is the ciphertext. He’d then transmit the initial start position, ABC, the encrypted message key, GHI, and then the ciphertext.
On the receiving side, the person decrypting the message would set the rotors to the first three letters received, ABC, and type in the next three letters, GHI. That outputs DEF. Looking above you’ll see that results in the rotor settings used when encrypting the message. So he sets the rotors to DEF and starts typing the ciphertext. The output is the plaintext message.
As an interesting side note for those who’ve seen the movie, The Imitation Game, you may recall the pivotal bar scene where Alan Turing learns that one operator always transmits the same letters at the beginning of his message, rather than random ones as they were supposed to. He was referring to the randomly chosen rotor positions we talk about above.
A fun way to see all these settings being applied before use is to watch the video in our article about an amazing Enigma in a wristwatch.
Have you had any experience with Enigma machines, or done encrypting in other ways? One thing is clear, Hackaday readers and writers alike get a certain pleasure from the Enigma machine — perhaps because it’s a sort of intelligent electromechanical beast or perhaps due to the delight to be had in encrypting and decrypting messages. Maybe the why of it is one puzzle you can clear up for us in the comments below?
Here are just a few of the older creations to be found here, starting with a toy that was hacked into an Enigma machine. Then there’s this Arduino based Enigma with LEDs disguised as nixie tubes. And here again is the amazing Enigma in a wristwatch.