How do the coding machines used in WWII work?

Cracking the code of code machines...
04 September 2017


An enigma machine, used by German forces in the Second World War to send coded messages



How do the coding machines used in WWII work?


Chris put this question to mathematician James Grime from Numberphile...

James - Yes. Well, there are more than one code machine in World War II. We’ll start with Enigma. So that’s the famous one. That’s the machine that was used by Nazi Germany in World War II to send their secret messages. So how did it work? Well mechanically, it’s just a circuit. It’s just a battery connected to a light. So you press a button, press a letter (A) for example, and the battery will connect to the letter (T), and it lights up. Now, what happens next is inside, there's a wheel and that wheel will turn. Now inside the wheel is full of wiring. So that’s where all the wiring is. So when that wheel turns, all the wiring gets turned which means the battery is connected to a different light. Which means if I press (A) again, it will become a different code letter. So, it’s constantly changing. That’s what made Enigma so difficult to decode.

Chris - So, how did you decode it then if you didn’t know where they started on the wheel?

James - So to decode, what you need to know is you need to know the correct starting position. So maybe miles away, you have your second German officer. They have an Enigma machine as well, set up exactly the same way as the first one. Then they type in the code, it will decode the message for them because mathematically, what the Enigma machine does is it turns 26 letters of the alphabet into 13 pairs. So, if I press (A) and it becomes (T), then (T) will become (A). So, it codes and decodes itself.

Chris - I see, right. When Alan Turing and his colleagues broke this code famously, how did they do it? What was the breakthrough?

James - So, well I think I should, just to be fair, we should mention that the Polish did this first. The Polish actually broke the code in 1932. So long before World War II, fantastically though, they managed to work out how the machine worked without ever seeing the machine, just from the codes alone. Love that! Just completely will be able to reverse engineer how the machine worked itself and then they could build their own replicas. The Polish did have methods to break those codes. Those methods were a little bit fragile and were likely to stop working. So this is what the British needed to do. They needed to come up with a method that could replace those Polish methods. Alan Turing had a method that used a flaw in the machine. I talked how the machine connects one letter to another in a pair. Well it makes 13 pairs, this means that a letter cannot be connected to itself. Now that was just a small clue. That’s not much. It’s a little clue, but it’s just enough to start breaking the code.

Chris - And so, how did they do it then? Because you still don’t know if you see a string of what appear to be random numbers or gibberish, how do you work out what was connected to what, the day that they wrote that message, where the rotor was effectively?

James - So, what you have to do is make a guess. So you guess a word or phrase that might be in that message. What the Germans would do in 6:00 o’clock in the morning, every morning, they would send a weather report. So, it was a standard letter. It was a standard form. You knew what that weather report said apart from the actual weather and you knew what that said. So you could use a phrase in that weather report and you will try and find it where it fits in the code. And we have a clue, a letter can't be itself. So if we use the word ‘weather’, or ‘Wetter’ in German, we know that a (W) can't become a (W), an (E) can't become an (E). So we can find where it fits. We can't have a matching letter. That’s not allowed. We find a match or when we find a position where it fits without a match, that bit of code might be the word ‘weather’. Now, we need to find the correct setting that makes that true.

Chris - So the weather is always our downfall, isn’t it? Thank you very much.

James - It’s very useful.

Chris - Jess, quickly.

Jess - Do you house an Enigma machine? Do you have one?

James - I do look after an Enigma machine.

Jess - Pretty cool!

James - That is cool. It is cool, isn’t it?

Chris - I think I've seen one. Simon Singh brought one to a talk we organised.

Jess - I think it’s that one.

Chris - It probably was, I think. So very impressive.

James - It may well have been the same machine that I look after.


Add a comment