Imagine you’re a codebreaker in World War II, trying to read your enemy’s messages. All the words appear as gibberish, and each letter you see transforms into a different one each time it’s typed. You’ve intercepted thousands of these messages, but that’s of no help unless you can decipher them. Somewhere in these messages are German commands and plans, and understanding them would be the key to stopping submarines, air raids, and gaining an upper hand in future battles. If you could crack the code, your side would have the upper hand in every future confrontation, knowing what the enemy planned to do before they even did it. These were the stakes the Allied codebreakers of World War II faced. Using different mathematical tools like statistics and group theory, incredible observations that exploited the behavior of German operators, and powerful computers like the Colossus, Allied codebreakers were able to crack German codes and give their side an advantage in the war.
Why would a country spend precious time and resources on centralized codebreaking operations? Wouldn’t it make more sense to pour the resources into researching better weapons or directly helping the troops on the front lines? In reality, codebreaking was just as important. In World War II, every major military decision was transmitted through coded messages. Orders for troop movements, submarine attacks, and air raids all passed through encrypted radio channels. If the codes could be broken, the Allies would know what the Axis planned to do and prepare for it before they could act. At the center of this were two machines: the Enigma, a more widely deployed machine used by the German Army, Navy, and Air Force, and the Lorenz cipher, used for the most important of German communications, like those between the top generals of the German High Command and with Hitler himself.

The Enigma

Lorenz cipher machine
The Enigma was a typewriter-like device with a series of three to five rotating wheels (called rotors), which changed position after every letter was typed. This meant that typing the same letter twice would produce two entirely different results, producing a completely incomprehensible code when it was finished. Additionally, its settings would change daily, making what seemed to be an entirely new code every day. There were over 1020 possible settings for the Enigma, so many that even testing a trillion possibilities a second, it would never be able to be cracked with brute force alone.
The most strategic communications, which would be the most game-changing, were encrypted using a different machine: the Lorenz cipher. These were the messages between top German Generals and with Hitler himself. It was even more complex, with twelve wheels, divided into regular and irregular stepping wheels. Decrypting this would need much more work than the Enigma, and the Allies would have to build the world’s first large-scale electronic digital computer to crack it.
The Germans made their own attempts at codebreaking, but had a less centralized operation than the Allies, with their codebreaking operations being dispersed through various competing agencies. This was partially sparked by overconfidence, as they believed the Enigma was unbreakable, which made them underestimate both their own vulnerability to codebreaking and the importance of codebreaking as a whole. This meant that while German codebreakers saw some success, breaking British naval codes early in the war, they largely fell flat, with the largest and most successful operations of the war being conducted by the Allies.
The attack on Enigma was made possible by the calculations and observations of a group of brilliant mathematicians. Each component of the machine could be described using permutation theory, a branch of combinatorics that studies how objects can be rearranged. Probability theory and logical deductions could also dramatically reduce the number of possible combinations that would have to be tested. Codebreakers at Bletchley Park, the center of Allied codebreaking efforts, would use these methods to attack the Enigma.

A Codebreaking Team at Bletchley Park

One of the first breakthroughs came from Polish mathematician Marian Rejewski. He started his work before the war had started, in preparation for possible German aggression towards Poland. Before the war, he cracked an early version of Enigma by modeling its wiring algebraically by treating each rotor as a mathematical function that transformed the letters. Then, using group theory, he reconstructed the wiring pattern, which would later give the Allies their first breakthrough. By the start of the war, however, the Germans had already improved the Enigma further, meaning more work was needed to break it again.
Even small and seemingly inconsequential observations could turn out to be incredibly important. One example was when British mathematician John Herivel realized he might be able to exploit the behavior of Enigma operators to get clues on how to break it. He thought that human operators might, out of laziness, gravitate towards certain starting positions, which could be exploited to speed up codebreaking. At the start of each day, Enigma operators were supposed to insert the rotors according to a set plan, then move them randomly, choosing a new position and sending it as a three-letter indicator at the start of their first message. From this, Herivel realized that if enough operators were lazy, only moving the rotors a bit or not at all, their three-letter indicators would cluster around the actual settings of the machine, narrowing down the possibilities for the code being used that day. Using this method, known as Herivel’s tip, Allied codebreakers could have a good guess at what the machine’s settings might be, making breaking the code much easier. This insight was a breakthrough, reducing the possible rotor configurations from 17,576 to just 20.

One of the most important mathematicians was Alan Turing. He used a combination of logic and probability to eliminate possibilities, shortening the time needed to break the code. To do this, he developed the Bombe. This machine could test hypotheses about likely plaintext fragments (essentially parts of messages believed to say a specific thing), called “cribs,” by simulating Enigma’s mechanical structure. The most famous of these cribs was the phrase “Heil Hitler,” which codebreakers knew to appear near the end of almost every message. This was one of many crucial pieces of text they could feed into the Bombe, making the decryption process much easier.
Another mathematician, Gordon Welchman, was able to notice patterns spanning across multiple messages. He introduced the “diagonal board,” an addition to the bomb that used parallel testing of interdependent rotor settings, treating Enigma’s wiring as a network of linked nodes. This further decreased the number of possible combinations that had to be tested.
Statistics also played a key role. Codebreakers used frequency analysis to estimate how likely certain pairs of letters were to appear together, and then could apply reasoning to prioritize the most probable configurations. Probability-based shortcuts, whether it was the Herivel Tip, frequency analysis, or Welchman’s diagonal board, were key to making the process possible.
While many advancements in cracking the Enigma were made by the computations and observations of human mathematicians, cracking the Lorenz cipher proved more complex. Unprecedented computing power would be needed to break it, leading to the creation of the Colossus computer: the world’s first large-scale electronic, digital, and programmable computer. Built by engineer Tommy Flowers and mathematician Max Newman, the Colossus could perform thousands of logical operations per second, analyzing patterns and testing hypotheses that would take weeks to do by hand. Behind the Colossus’s work was math, specifically Boolean logic and modular arithmetic. Put simply, the Lorenz cipher worked by shifting letters in different patterns using its 12 wheels. By translating these patterns into binary operations (1s and 0s), the Colossus could automatically compute, compare, and eliminate possibilities for how the Lorenz had encrypted the messages that were sent, eventually breaking the code.

The Colossus Computer
World War II codebreaking showed the power of math and human observations. Computational methods like Rejewski’s permutations, Turing’s Bombe machine, and the Colossus’s electronic computations, along with more logic-based approaches like Herivel’s Tip, were able to break both the Enigma and Lorenz, codes the Germans had believed were mathematically unbreakable. This provided crucial intelligence for the Allies, informing them of German attacks, battle plans, and strategy far in advance. It also allowed the Allies to confirm their successes, like when Allied codebreakers were able to confirm they had successfully tricked the Germans about where D-Day was occurring, as well as learn German troop locations before the attack. Ultimately, these mathematicians, despite working far from the front line, helped shorten the war and save countless lives.