DR. JAMES GRIME: 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 who 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 Numberphile.
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, and 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 code 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 things here at the top.
These things are called rotors.
And inside those rotors, try and imagine lots of wiring.
And it's all crisscrossed wiring as well.
Now, if I press a letter, have a look what happens.
The rotors move.
When this rotor does a full turn, it'll 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, is just a circuit.
Here is a battery.
You can see that's a modern battery in there.
We've converted this.
And 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.
It 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.
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 Numberphile,
were a 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.
That would travel miles away.
So now imagine a second German officer, maybe on a ship
somewhere in 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, Y-T-H-M-Y 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 would 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 would have
three rotors left.
And you multiply those numbers together.
So it's 5 times 4 times 3.
So there are 60 ways that you can put in three rotors from a
choice of five.
We have 26 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.
The 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 plugboard.
And it's like an old-fashioned telephone switchboard, like an
old patchboard.
We have 10 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 10 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.
So that means there are 6 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, 2 letters in a pair.
Well, if I swap 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.
Just 2 to 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 million, 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 are telling me that the Germans would send each other
messages like Numberphile or send--
DR. JAMES GRIME: Yeah, they did that all the time.
-Or send the U-boat to this position or whatever.
But how were they telling each other their plug settings and
their starting rotor numbers?
DR. JAMES GRIME: 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, they 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.
And 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.
DR. JAMES GRIME: 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?
DR. JAMES GRIME: 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 a letter K--