How Long Would It Take You To Crack The Enigma Machine
Mathematics / By Hannah Furness / September 20, 2021 September 20, 2021
By now almost everyone would have heard of the Enigma Machine, be it from your love for Benedict Cumberbatch, who played Alan Turing in the Imitation Game, or maybe you have a passion for code breaking.
Bletchley Park – Where the code breaking took place [1]
Now I myself am a big fan of Cumberbatch and watching him in the Imitation Game led me to wonder, how long would it have taken me to crack the enigma machine?
First we need to understand what we're up against, I'll go through how the machine functioned.
If you pressed a letter on the keyboard it would send an electrical signal through the plugboard to the rotors, this would cause the rightmost rotor to shift once. The signal would then flow through the three rotors, bounce back off of the reflector, through the rotors and plugboard once again and light up a lamp on the board. Easy right?
How does the machine work?
Original Enigma machine [2]
Let's break it down, the first obstacle we face is the plugboard. This has 10 wires which connect 20 letters into pairs, two letters in a pair will swap over when input into the machine.
The next items we face are the three rotors. When this machine was being used in the army they had five rotors to choose from, each of these rotors is wired in a completely different way. It took some espionage to figure out the way in which the rotors were wired, but essentially each rotor takes the letter that has been input into the machine and switches it to a different one a certain number of places down the alphabet. Once this has been done the rotor shifts down one place, once the first rotor completes a full turn this triggers the next one to shift and so on.
So how many combinations do we need to try?
Let's do the math!! We can figure out how many settings on the Enigma Machine you would have to try to crack the code…
First, we need to place the rotors into the machine. We have five to choose from and the order in which we pick them matters. For the first rotor space we have five to choose from, for the second space we have four to choose from and for the third space we have three rotors to choose from. So overall there are $5\times 4\times 3 = 60$ ways to put the rotors into the machine.
Now each of these rotors can be put in 26 different ways, correlating to the 26 different letters of the alphabet. So we get $26\times 26\times 26 = 17,576$ different starting positions for the three rotors.
Labelled Enigma Machine [3]
Finally we have the Plugboard, mathematically this is the most complex to explain so bare with me. We have ten wires to connect, each with two ends. So, the amount of plugs available decreases every time you plug one end in. There are 26 ways of plugging the first end in and 25 left for the other end. So there are $26\times 25$ ways of plugging this in, but then we are counting each combination twice as it doesn't matter which end we plug in first, so we have to divide this by two. This gives us $\frac{26\times 25}{2} = 325$ different ways to plug the first wire in.
This process then repeats for the other nine wires. For the second wire we have 24 plugs for one end, 23 for the other divide this by two and we get $\frac{24\times 23}{2} = 276$. We continue this process until we get to the tenth wire which will have $\frac{8\times 7}{2}$ ways of plugging it in. This gives us $\frac{26\times 25}{2} \times \frac{24\times 23}{2} \times \frac{22\times 21}{2} \times … \times \frac{8\times 7}{2}$.
Unlike the rotors, it doesn't matter the order in which the wires are plugged in. At the moment we have accounted for it so we need to divide by the amount of choices we had for each wire. We had ten choices for the first pair to plug in, nine choices for the next pair, and so on, down to one pair for the last. So we've actually repeated ourselves $10 \times 9\times 8 \times … \times 2 \times 1$ times. This can be written as $10!$ (10 factorial). For a more in depth explanation of this, see Georgia's article "How Unique Is A Pack Of Cards?". We then divide the previous calculation by $10!$ to get $$ \frac{\frac{26\times 25}{2} \times \frac{24\times 23}{2} \times \frac{22\times 21}{2} \times … \times \frac{8\times 7}{2}} {10!} = 150,738,274,937,250.$$
To find the total number of settings we multiply the three figures together to get…
$$60 \times 17,576 \times 150,738,274,937,250 = 158,962,555,217,826,360,000.$$
Now that's a big number, but it's hard to put into perspective just how big it really is.
If you tried a different setting every second it would take you approximately 5,040,669,559,165 years. Which, I think we can agree is not exactly feasible. Even if we took the entire population of the world, which is around 7.8 billion, and we asked them to all try a combination of the enigma machine every second, it would still take 646 years to try every single possible combination!
How did Alan Turing crack the Enigma Machine?
Turing's 'Bombe' machine [4]
Alan Turing and the other mathematicicans working on cracking the Enigma only had 24 hours at a time before the original settings for the machine were switched and all the code breaking they had completed that day became useless. The Enigma Machine had one fatal flaw which Turing used to his advantage, a letter could not be coded to itself. Turing and his team also realised that the messages sent by the Germans would take the same format each day, so they would look for common words or phrases such as 'Wetterbericht', which means weather report in German, and line these up with the code so that none of the letters matched because they could not be coded onto themselves.
This is of course a huge simplification of the work Turing and his team had to go though to crack the code; they may not have managed without using the 'Bomba' created by a team of Polish code breakers before World War 2 began. Turing created a huge machine called the 'Bombe' which managed to crack the enigma code within 20 minutes, he used the work of the Polish mathematicians to help create this massive machine. Both the Bombe and the Bomba essentially acted like simple computers. The Bomba would go through and try every position the rotor could be in to try and crack the code. Initially, when the Enigma Machines only had three rotors, the Bombas worked really well. They would use six, one for each combination of rotors, and the process would only take up to two hours. However, when the Germans ramped up their security and added more rotors the amount of Bombas it would take to crack the code in the same amount of time changed to 60. Simply making and investing in these machines and their operators was not worth it. The Bombe acted in almost the same way as the Bomba but it made use of the repeating messages such as the 'Wetterbericht' example I used previously. By understanding where certain phrases would appear in the text and knowing that a letter could not be encrypted onto itself, the amount of combinations that needed to be tried reduced significantly as the Bombe could be programmed to take this into account.
By cracking the German code it is believed that Turing and his team shortened the Second World War by up to two years. I think now we can truly appreciate the mammoth task Alan Turing was presented with, when trying to crack the Enigma Machine!
References and Related Text
[1] https://www.britannica.com/place/Bletchley-Park
[2] https://commons.wikimedia.org/wiki/File:Naval_ENIGMA_machine_(3317898024).jpg
[3] https://jgandrews.com/posts/the-enigma-machine/
[4] https://commons.wikimedia.org/wiki/File:TuringBombeBletchleyPark.jpg
Numberphile Video: https://www.youtube.com/watch?v=G2_Q9FoD-oQ&t=12s
More Information on the Bombe: http://www.rutherfordjournal.org/article030108.html
More Information on the Bomba: https://www.bcs.org/articles-opinion-and-research/the-enigma-of-the-polish-bomba/
Hannah Furness
Hannah is currently in her second year at UEA studying Mathematics. Fluid Flow and Differential Equations have been her favourite modules so far, and she can't wait to learn about cryptography in third year. Alongside her studies, she enjoys watching and taking part in musical theatre and dance. Her most recent project has been playing the role of Otto in Spring Awakening.
Copyright © 2022 School of Mathematics, University of East Anglia.
We launched the site. Excited? So are we!
Institute of Mathematics and its Applications Prizes: William Card, Kayleigh Jones;
The Graham Everest Memorial Prizes: Hector Betteridge, Jared Carpenter, Shay Jordan;
The School of Mathematics Year 1-3 Prizes: Callum Gorham, Jake Harvey-Le Grice, Luke Kelly, Ben Phair, Tia Seagust;
The School of Mathematics Final Assessment Prizes: Bradley Brown, Katie Orbell, Kraig Wymer-Webb;
MMath Final Year Project Prize: Edward Betteridge, Bailey Franke;
The Dominic Russell Prizes: Molly Leeder, Dylon Thoo;
The Felix Klein Prize: Katie Orbell.