This is such an inspiring story because it shows how mathematicians can save lives. We're talking about one of the most famous cipher machines of all time. It's a code machine called the Enigma machine, used by Nazi Germany in World War II to send secret coded messages. And we've got one over here.
This is not a copy. This is not a replica. This is an original Enigma machine actually used in World War II. This was made in 1936. It's an army Enigma machine.
Let's see how it works. So this belongs to a man called Simon Singh. He's an author. He writes popular science books.
And he lends it to the University of Cambridge, where I work. This was found. in a French field, I was told, by an American cryptographer after the war, and he took it home.
So I guess he took it home as his souvenir. Yoink, that's mine. The guy found it died about 12 years ago, and when he died, that's when Simon Singh bought the machine. We're going to send a message.
Now, we were talking about what to send before, so we send them a file. Let's turn this into Enigma code. So I'm going to type in N to begin with, and if you can see there, the letter Y lights up. So n becomes y.
Your code lights up. Let's write that down. Let's do the next letter, u.
u becomes t. Let's do m. And I've got h this time.
b. And e. is w. Notice here, we had y turn up twice. And they turned up for two different letters.
So n became y. Then later on, e became y. That's unusual. The other unusual thing you may notice is that the two e's in numberphile have turned into two different letters.
So here, E became Y, but the second E became W. Now, this is why the Germans thought they had an unbreakable code. Old-fashioned codes in the past, pen and paper codes. that they used to use.
If you had the same letter, it would become the same letter in the code. Enigma is different. Probably each time you did it, you would get a completely different code. Now, if we can break this code, and by we I mean the Polish, the British and the Americans, if we can break this code in World War II, we'll be able to read those German secret messages, which is what we did. So let me show you how this machine works.
Let me open up the machine. So we have three letters. three things here at the top.
These things are called rotors, and inside those rotors, try and imagine lots of wiring, and it's all criss-crossed wiring as well. Now, if I press a letter, have a look at what happens. The rotors move. When this rotor does a full turn, it will kick the next rotor one place, and then the right-hand rotor keeps going.
Eventually, the middle rotor does a full turn, and it will kick the left-hand rotor one place. So a fast rotor, a middle rotor, and a slow rotor. imagine it like it's hands on a clock like you've got a minute hand and an hour hand and a second hand that's the idea brilliant machine though this is all it is really it's just a circuit here is a battery you can see that's a modern battery in there we've converted this and this This battery is connected to a bulb, and it lights up. It's the most simple thing you can make. A battery and a bulb, the bulb lights up, and that's all it is.
The clever bit is the wires of the circuit are inside the rotors. So when the wires turn, the battery will connect to a different bulb. Let's try and see that happen.
So I'm going to turn the wires, and the battery connects to this bulb. Do it again. I'm going to turn the wires.
And the battery connects to this bulb. Changes. Do it again. Turn the wires, and the battery connects to this bulb. And that's why it changes each time, because it has moving parts inside.
But otherwise, it's just a simple circuit. I think we need to know how to decode. This would be no good if we can't decode our message.
So let's do that. Right. First of all, we're going to take our code here.
We need to know what the setting was. Now, if you notice in the little windows, we have three numbers. It's like a combination. lock like a bike lock. Now I took a note of what those three numbers were.
Those three numbers, when we started writing number file, were 13, 9, and 21. So the idea is you would type in your message and you would get a code. The machine itself doesn't transmit, so you would have to write that code on a piece of paper. So that piece of paper would be given to the radio operator, who would then transmit the message by radio, by Morse code. would travel miles away so now imagine a second German officer maybe on a ship somewhere in the The ocean.
Now he's tuning into that radio signal. He can hear the code, it's coming in, and he writes it down. Now this second officer will have an Enigma machine as well.
And his Enigma machine is exactly the same as the first one. So, there's something I have to do. I now need to set these rotors to the correct position. So we've got this code over here, YTHMY. And whatever.
Let's type that into the machine this time and see what happens. OK, so we start with y. y becomes n. t becomes u. h becomes m.
m in the code is a b. y, i, f, and w, finally. is E. So each rotor has 26 starting places. In fact, these rotors come out and swap over.
In fact, again, they had five rotors to pick from. They had a box of five rotors. You'd pick three from a box of five.
And already, we've got thousands of settings. And each one will produce a different code. So we're going to work out those combinations.
So the first thing I said was we pick three. rotors from a box of five. In the first slot you would have five rotors to pick from. Once you've picked that, in the second place you would have four rotors to pick from and in the final place, the third place, you will have three rotors left and you multiply those numbers together.
So it's five times four times three. So there are sixty ways that you can put in three rotors from a choice of five. We have twenty-six starting positions for each rotor.
So we have 26 choices for the first one, 26 choices for the second one, and 26 choices for the third one. And if you do that, you get 26 cubed, which is 17,576. It gets worse, because the military, the army, air force, navy, had something extra.
For commercial machines, if you were a bank or a business, you could buy an Enigma machine to use yourself to send your own secrets. But the military had an extra bit. They had this thing at the front of the machine. Now this is called a plug board.
And what it is, it's like an old-fashioned telephone switch board, like an old patch board. We have ten of these wires. And each of these wires connect two letters into a pair. So in this case, you might see the letter Q is going to connect with the letter E.
Now you make ten of those pairs. Two letters in a pair. will swap over. So if Q is connected to E, then Q and E would swap over.
That's an extra level of scrambling only available to the military. Now this had the most number of combinations. Now this calculation is going to be the hardest calculation, but we can do it. So there are 26 letters in the alphabet.
How many ways to arrange 26 letters? Well, it's 26 times 25 times 24, all the way down to 1. That's 26 factorial. But we don't want every combination of 26 letters.
We only want to make 10 pairs. That means there are six letters left over, which we don't care about. Because we don't care about them, that means we're allowed to divide. And we're going to divide by 6 factorial. Now there are 10 pairs.
We don't care what order those 10 pairs are in. Because we don't care about it, we can divide by 10 factorial. And the last thing to divide by, two letters in a pair. Well, if I swapped them over, that would still be the same pair.
If I had A and B, that's the same as B and A. That's still the same pair. So I can divide by 2. And I do that for each pair.
There's 10 pairs. So I'm going to divide by 2, 10 times, which is 2 to the power 10. And that is how many ways that you can connect 20 letters into 10 pairs on the front of the machine. How big is that number?
Shall we do that? 150 trillion, 738 billion, 274 million, 937,250. So the total, 158 quintillion, 962 quadrillion, 555 trillion, 217 billion. 826,360,000 flat. That is the total number of ways that you can set the Enigma machine.
This would be an army Enigma machine around... About 1939. You were telling me that the Germans would send each other messages like numberphile or send... Yeah, they did that all the time. Or you know, send the U-boat to this position or whatever. But how were they telling each other their...
their plug settings, and their starting rotor numbers. So this is very important. So these two people who are miles apart need to have the same setting.
Now, the setting was written down for you on a piece of paper. What they would have is a sheet of paper like that. and it would be a big sheet of paper for each day of the month.
So it was a monthly sheet. For each day of the month, it told you how to set the machine for that day. If you didn't have this sheet of paper, you wouldn't know what the setting was that you had to use for that day.
A nice little story, the Navy would write these code books in soluble ink. So if you get sunk, if you get caught, if you throw the code book into water, that's how you keep the secret. It sounds to me that all you need... is an Enigma machine and a copy of that book and you know everything they're saying? You would do.
So if you had the machine and you had that code sheet you would be able to decode all the messages. Fantastic, great. But we had the machine and once we've had the machine we can pull it apart and find out how it works, great. But it was getting those code sheets that was difficult.
They were monthly, they would change every month. If you did capture them, which we did occasionally, You could use it until it runs out, but without a code sheet, you would have to break the code, and you would have to do that with mathematics. What was the key?
What was wrong with Enigma? What was its weakness? Let's have a look at what the flaw is in the Enigma machine. So the Germans thought it was unbreakable, but there is a flaw.
If I press the letter K...