How Rejewski and Turing Used Math to Crack the Enigma Code

During World War II, the German military relied on the Enigma machine to encrypt its communications, believing the cipher to be entirely unbreakable. However, the code was ultimately defeated not by espionage, but by pure mathematics. This article provides a clear look at how Polish mathematician Marian Rejewski first broke the Enigma in the 1930s using permutation group theory, and how British mathematician Alan Turing later expanded on this work using logic and Bayesian statistics to defeat the upgraded wartime Enigma.

The Mathematical Nature of the Enigma

To understand how mathematics broke the Enigma, one must first view the machine as a mathematical function. The Enigma was an electromechanical rotor cipher machine. When an operator pressed a key, an electrical current passed through a plugboard, a series of rotating wheels (rotors), and a reflector to light up a different letter.

Every time a key was pressed, the rotors stepped forward, changing the electrical pathway entirely. Mathematically, the Enigma generated a polyalphabetic substitution cipher. Each state of the machine represented a specific permutation—a complete rearrangement of the 26 letters of the alphabet. With billions of possible starting configurations, guessing the settings by brute force was impossible.

Marian Rejewski and Group Theory

Prior to the 1930s, codebreaking was the domain of linguists who looked for patterns in language. Poland’s Cipher Bureau changed history by hiring mathematicians, including Marian Rejewski, who approached the Enigma as an algebraic equation.

Rejewski exploited a procedural flaw in how German operators sent messages. At the start of each transmission, the operator chose a three-letter key and typed it twice (for example, KCH KCH) to ensure the receiving operator got the correct setting. Because the Enigma rotors stepped with every keypress, the two identical three-letter sequences were encrypted differently, appearing as something like PQL ZMU.

Rejewski realized that the first and fourth letters (P and Z), the second and fifth (Q and M), and the third and sixth (L and U) were originally the same letters. By analyzing enough messages sent on the same day, he could link these pairs together into chains, or "cycles."

Using permutation group theory, Rejewski applied a fundamental theorem: two permutations that are "conjugate" (structurally related in a specific algebraic way) will always have the exact same cycle lengths. Crucially, the Enigma's plugboard—which swapped pairs of letters and created the vast majority of the machine's mathematical possibilities—only changed the letters inside the cycles, not the lengths of the cycles themselves.

By cataloging the lengths of these cycles, Rejewski completely bypassed the plugboard. He used systems of permutation equations to reverse-engineer the physical wiring of the German military rotors without ever having seen one in person. He then invented the bomba, an electromechanical device that used these mathematical cycles to find the daily Enigma keys in a matter of hours.

Alan Turing, Logic, and Bayesian Statistics

Just before the outbreak of World War II, the Germans increased the complexity of the Enigma by adding more rotors and eventually abandoning the double-enciphered message key. The Polish bomba could no longer keep up, and the Polish mathematicians shared their work with British and French allies.

At Bletchley Park, Alan Turing realized a new approach was needed that did not rely on the operator typing the key twice. Instead, Turing focused on "cribs"—known or guessed words in the original German text, such as Wetterbericht (weather report) or Heil Hitler.

Turing combined cribs with a fatal mathematical flaw in the Enigma's reflector: a letter could never be encrypted as itself. If an 'A' was pressed, the output could be any letter except 'A'.

Mechanized Logic

Turing used this rule to line up a crib against a piece of intercepted ciphertext until no letter matched itself. From this alignment, he mapped out loops of letter pairings. He then designed the British Bombe, a massive electromechanical machine that used electrical circuits to test these loops.

The Bombe worked by proof of contradiction. It assumed a specific rotor setting and assumed a specific plugboard wire (e.g., 'A' is connected to 'T'). The electrical current would instantly flow through the loops of the crib, forcing other connections. If this chain reaction resulted in a logical contradiction (e.g., proving 'A' is also connected to 'Z'), the machine rejected that rotor setting and moved to the next. Only settings that produced no mathematical contradictions caused the machine to stop, alerting operators to a potential match.

Banburismus and Statistics

Even with the Bombe, there were too many rotor combinations to test quickly, particularly for the complex Naval Enigma. To solve this, Turing invented a statistical technique called Banburismus to figure out which rotors were in the machine before running the Bombe.

Banburismus was a practical application of Bayesian statistics and probability theory. Turing knew that real languages are not random; letters like 'E' appear far more often than 'Q'. Consequently, if two different messages were encrypted using the exact same rotor positions, the rate at which their encrypted letters matched at the same positions would be slightly higher than pure chance (about 1 in 17, rather than 1 in 26).

Turing punched intercepted messages onto long paper sheets and slid them over one another to find matching letters. To calculate the probability that these matches were not just coincidences, he invented a mathematical unit of weight of evidence called the "ban" (and "deciban").

Using Bayes' theorem, Turing assigned deciban scores to letter coincidences. As operators found more matches, they added the scores together. Once the score crossed a specific statistical threshold, they knew with near certainty that the two messages shared the same rotor settings, drastically reducing the number of configurations the Bombe needed to test.

Summary

Marian Rejewski and Alan Turing transformed cryptography from a linguistic art into a hard science. Rejewski used the abstract algebra of group theory to strip away the Enigma's complexity and expose its internal wiring. When the Germans closed the loopholes Rejewski used, Turing applied formal logic and Bayesian statistics to weaponize the predictable nature of human language against the machine, automating the math that helped win the war.