Skip to main content
Basic Classic Symmetric Advanced

The Enigma Machine

Learn how the Enigma machine worked: the WWII German cipher machine that produced a different substitution alphabet for every single keystroke. Its defeat by Alan Turing and Bletchley Park changed the course of the war.

PL
Pashalis Laoutaris
August 21, 2026
16 min read

Interactive Enigma Machine Visualizer

🔐 Enigma Machine Visualizer

5
Enter text and click a button to start!
Rotor I
A
Rotor II
A
Rotor III
A
Lampboard
HELLO

The Enigma Machine: A Different Cipher for Every Keystroke

Introduction

Every polyalphabetic cipher in this series (Vigenère, Beaufort, Autokey) varies its substitution using a key, something that has to be written down, shared, and referenced. The Enigma machine, used extensively by Nazi Germany during World War II, took the same core idea, a different substitution alphabet for each letter, and built it into an electromechanical device. That device generated new substitution alphabets automatically, one for every single keystroke, from a small set of physical rotor settings. Its defeat was led by Polish mathematicians before the war, and then by Alan Turing and the codebreakers at Bletchley Park. It’s one of the most consequential achievements in the history of cryptography.

Table of Contents

How the Enigma Machine Works

An Enigma machine looks like a typewriter wired to a set of rotating wheels. Every time an operator presses a key, an electrical signal travels through a fixed sequence of components: a plugboard, three rotors, a reflector, and back through the same three rotors. Then it lights up a single lamp showing the output letter. Critically, before the signal even starts its journey, the rightmost rotor physically rotates by one position. That means the very same key, pressed twice in a row, almost never produces the same output letter twice.

Interactive Visualizer

Try it above. Set the three rotors’ starting positions, optionally add plugboard pairs, and type a message. Watch the rotor dials advance with every keystroke and the lampboard light up the corresponding output letter.

The Signal Path: One Keystroke, Step by Step

For every keypress, the electrical signal travels through the machine in a fixed order:

  1. Plugboard (Steckerbrett): swaps pairs of letters the operator has physically connected with cables (for example, swapping A and B). This happens before the signal reaches the rotors at all.
  2. Rotor III (rightmost) → Rotor II (middle) → Rotor I (leftmost): the signal passes through each rotor’s internal wiring, each one performing its own fixed substitution, offset by that rotor’s current rotational position.
  3. Reflector (Umkehrwalze): a fixed wiring that sends the signal back the way it came, through a different path than it arrived by. Critically, the reflector never sends a letter back to itself.
  4. Rotor I → Rotor II → Rotor III: the signal passes back through all three rotors in reverse.
  5. Plugboard again: one final swap, using the same cable pairs as step 1.
  6. Lamp: the resulting letter’s lamp lights up.

Because the rotors’ positions changed before this whole sequence began, the exact substitution performed in steps 2-4 is different for almost every keystroke.

The enigma machine

Why the Rotors Are the Key Innovation

Each rotor is a physical disk with 26 electrical contacts on each face, internally wired to connect each input contact to a different output contact. That’s a fixed substitution alphabet, baked into the rotor’s construction. The real innovation is what happens between rotors. Each rotor rotates independently and at a different rate, much like the wheels of a mechanical odometer. Because of that, the combined substitution performed by all three rotors together changes with nearly every keystroke. The operator never has to think about a “key” the way a Vigenère operator manually tracks keyword position. The machine does the equivalent of automatically advancing through an enormous number of different Vigenère-style alphabets, purely mechanically.

Beyond a rotor’s starting position, real Enigma machines had one more adjustable parameter per rotor: the ring setting (Ringstellung). This is an offset between the rotor’s internal wiring and the letter printed on its outer ring, effectively shifting where the notch falls relative to the visible letter. Ring settings were part of the daily key alongside rotor choice, rotor order, starting positions, and plugboard connections. They matter historically too: getting them wrong was a genuine source of operator error. For clarity, this article and the visualizer above fix all ring settings to their neutral value (A). This is a standard simplification for teaching the mechanism: the signal path, stepping logic, and self-reciprocal property all work identically regardless of ring setting.

It’s also worth noting that “Enigma” wasn’t a single machine. Commercial and diplomatic versions predating the war lacked a plugboard entirely and offered fewer rotor choices. The German military’s later machines, including four-rotor naval variants, added complexity well beyond what’s covered here. This article focuses on the classic three-rotor military Enigma I with plugboard. That’s the configuration most commonly discussed and the one Bletchley Park spent the most effort against.

The Stepping Mechanism (and Its Famous Quirk)

The rightmost rotor advances by one position on every single keystroke. When it reaches a specific position called its notch, it mechanically pushes the middle rotor forward by one position too, much like a car odometer’s ones-digit carrying into the tens-digit. If the middle rotor is itself sitting at its own notch position at that moment, it triggers a “double-step”: the middle rotor advances again on its own, and it also carries the leftmost rotor forward. This happens even though the rightmost rotor’s notch wasn’t involved that time. This genuinely quirky mechanical behavior, a direct consequence of how the physical ratchet-and-pawl mechanism was built, is faithfully reproduced in the visualizer above.

A Worked Example

Using the historical Enigma I wiring for Rotors I, II, and III (left to right), Reflector B, all rotors starting at position A, ring settings at their neutral value (A), and no plugboard connections, encrypting “HELLO”:

Because the rightmost rotor steps before each letter is processed, the rotor positions actually used for each of the five letters are already one step ahead of where the dials started:

Letter H E L L O
Rotor positions (I, II, III) A A B A A C A A D A A E A A F

Only the rightmost rotor moves here. Five letters isn’t enough for it to reach Rotor III’s notch (V) and carry into the middle rotor. So the middle and left rotors stay put at A throughout this particular message.

“HELLO” → “ILBDA”

Running the exact same settings (rotors reset to AAA) against “ILBDA” recovers “HELLO” exactly. Notice something else: none of the five output letters matches its corresponding input letter (H≠I, E≠L, L≠B, L≠D, O≠A). This is not a coincidence. The reflector’s wiring guarantees mathematically that no letter can ever encrypt to itself, a property that turned out to be one of Enigma’s most consequential weaknesses.

Why Enigma Is Self-Reciprocal

Just like the Beaufort cipher earlier in this series, Enigma performs the exact same operation for both encryption and decryption. There’s no separate “decrypt mode” on the machine at all. This works because the reflector makes the entire signal path an involution. Whatever path a signal takes forward through the rotors and back is exactly reversible. That’s because the reflector guarantees the return trip uses different wiring than the outbound trip, in a way that’s symmetric. As long as both operators start with the same rotor positions and the same plugboard settings, running ciphertext back through the machine reproduces the original plaintext exactly. This is precisely why real Enigma operators needed to agree on daily settings in advance. The machine itself doesn’t distinguish between “encrypting” and “decrypting.”

Pros and Cons Analysis

Advantages Disadvantages
Astronomically Large Keyspace: Rotor selection, rotor order, starting positions, ring settings, and plugboard connections together produced a number of possible configurations in the hundreds of trillions, dwarfing every hand cipher in this series No Letter Ever Encrypts to Itself: The reflector’s fixed-point-free property, while seeming like added security, actually handed cryptanalysts a powerful constraint that eliminated huge numbers of candidate plaintexts instantly
Self-Reciprocal Operation: One machine, one procedure, for both encrypting and decrypting. Genuinely practical for battlefield use Operational Procedures Leaked Structure: Predictable message formats, repeated greetings, weather report boilerplate, and other routine operator habits gave cryptanalysts consistent “cribs” (known or guessed plaintext) to work from
A Different Substitution Almost Every Keystroke: Far beyond what any hand cipher in this series could achieve, defeating simple frequency analysis completely Never-Repeating Rotor Positions Within Reasonable Message Lengths Still Have Exploitable Structure: Given enough intercepted traffic and known cribs, the underlying rotor wiring and daily settings could be mathematically reconstructed
Genuine Historical and Engineering Significance: A real, deployed, electromechanical cipher machine whose cryptanalysis directly shaped the outcome of World War II Settings Reused Across a Day’s Traffic: All messages sent under the same daily key shared the same underlying machine state space, letting cryptanalysts combine evidence across many intercepted messages

How Enigma Was Actually Broken

Enigma’s defeat was not a single dramatic mathematical trick. It was a sustained, evolving intelligence effort spanning years and multiple countries:

  • Polish cryptanalysts, led by mathematician Marian Rejewski, made the foundational breakthroughs in the 1930s. They developed mathematical techniques, including using group theory to analyze the machine’s permutation structure, and built early electromechanical devices to help find daily settings. This work drew partly on procedural weaknesses in how German operators initially used the machine.
  • Bletchley Park, the British wartime codebreaking center, inherited and dramatically extended this work once the Poles shared their techniques shortly before the war began. Alan Turing was central to designing the Bombe, an electromechanical machine that automated the search for daily rotor settings. It worked by exploiting known or guessed plaintext fragments (“cribs”): routine phrases German operators used predictably, like standard weather-report openings.
  • The “no letter encrypts to itself” property directly enabled crib-based attacks: if a cryptanalyst guessed a crib might appear at a certain position in a message, they could instantly rule out that alignment if any letter of the crib matched its corresponding ciphertext letter. That’s because such a match is mathematically impossible on a real Enigma machine. This constraint dramatically narrowed the search space the Bombe had to explore. Concretely: suppose a cryptanalyst suspects the crib “WETTER” (German for “weather,” a routine word in military reports) appears starting at a particular position in a ciphertext. Suppose the ciphertext at that exact position happens to contain a “W,” lined up with the crib’s own “W.” That alignment can be discarded immediately, with no further computation needed, since Enigma could never have encrypted W to W. Sliding the crib just one position over and repeating this check quickly eliminates the vast majority of candidate alignments, leaving only a handful worth testing on the Bombe itself.
  • Operational discipline failures compounded the mathematical weaknesses: reused message keys, predictable settings choices by lazy or rushed operators, and consistent message formatting gave the Allies repeated openings that a perfectly disciplined operational procedure would have denied them.

This mirrors a theme that recurs throughout this series: even a cipher with genuine mathematical and engineering sophistication can be undermined by real-world usage patterns and operational shortcuts, independent of the underlying cryptographic strength.

Modern Relevance

The Enigma machine secures nothing today, but its legacy is enormous:

  • It’s arguably the most historically consequential cipher ever broken. The intelligence gained from reading Enigma traffic (codenamed Ultra) is widely credited with shortening World War II and saving substantial numbers of lives.
  • It directly catalyzed the birth of modern computing: the codebreaking effort at Bletchley Park, including Turing’s foundational theoretical work and the practical engineering of the Bombe and later Colossus, is a direct ancestor of programmable electronic computing.
  • It remains the canonical teaching example for rotor-based polyalphabetic ciphers, illustrating both the genuine strength that mechanical automation can add over hand ciphers, and the equally real ways that mathematical elegance (like the reflector’s involution property) can create exploitable structure.

Python Implementation

This follows the signal path from earlier in this article step by step: plugboard, three rotors forward, reflector, three rotors backward, plugboard again, with the rotors stepping once before each letter. It uses the real historical wiring for Rotors I-III and Reflector B, with ring settings fixed at their neutral value as this article does throughout:

ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

ROTORS = [
    {'wiring': 'EKMFLGDQVZNTOWYHXUSPAIBRCJ', 'notch': 'Q'},  # Rotor I (leftmost)
    {'wiring': 'AJDKSIRUXBLHWTMCQGZNPYFVOE', 'notch': 'E'},  # Rotor II (middle)
    {'wiring': 'BDFHJLCPRTXVZNYEIWGAKMUSQO', 'notch': 'V'},  # Rotor III (rightmost)
]
REFLECTOR_B = 'YRUHQSLDPXNGOKMIEBFZCWVJAT'

def rotor_forward(rotor_index, pos, letter_index):
    wiring = ROTORS[rotor_index]['wiring']
    shifted = (letter_index + pos) % 26
    out_letter = wiring[shifted]
    return (ALPHABET.index(out_letter) - pos) % 26

def rotor_backward(rotor_index, pos, letter_index):
    wiring = ROTORS[rotor_index]['wiring']
    shifted = (letter_index + pos) % 26
    target_letter = ALPHABET[shifted]
    return (wiring.index(target_letter) - pos) % 26

def step_rotors(positions):
    """positions = [left, middle, right], each a 0-25 offset from 'A'."""
    notch_index = lambda i: ALPHABET.index(ROTORS[i]['notch'])
    right_at_notch = positions[2] == notch_index(2)
    middle_at_notch = positions[1] == notch_index(1)

    if middle_at_notch:
        # the famous double-step: the middle rotor carries the left one too
        positions[1] = (positions[1] + 1) % 26
        positions[0] = (positions[0] + 1) % 26
    elif right_at_notch:
        positions[1] = (positions[1] + 1) % 26
    positions[2] = (positions[2] + 1) % 26

def plug_swap(pairs, letter):
    return pairs.get(letter, letter)

def encrypt_letter(positions, plug_pairs, letter):
    idx = ALPHABET.index(plug_swap(plug_pairs, letter))

    idx = rotor_forward(2, positions[2], idx)
    idx = rotor_forward(1, positions[1], idx)
    idx = rotor_forward(0, positions[0], idx)

    idx = ALPHABET.index(REFLECTOR_B[idx])

    idx = rotor_backward(0, positions[0], idx)
    idx = rotor_backward(1, positions[1], idx)
    idx = rotor_backward(2, positions[2], idx)

    return plug_swap(plug_pairs, ALPHABET[idx])

def enigma_transform(text, start_positions, plug_pairs=None):
    """Self-reciprocal: run the identical settings again on the output to recover the input."""
    positions = list(start_positions)
    plug_pairs = plug_pairs or {}
    text = ''.join(c for c in text.upper() if c.isalpha())
    result = ''
    for char in text:
        step_rotors(positions)
        result += encrypt_letter(positions, plug_pairs, char)
    return result

if __name__ == "__main__":
    start_positions = [0, 0, 0]  # Rotors I, II, III all starting at 'A'
    plaintext = "HELLO"

    ciphertext = enigma_transform(plaintext, start_positions)
    recovered = enigma_transform(ciphertext, start_positions)

    print(f"Plaintext:  {plaintext}")
    print(f"Ciphertext: {ciphertext}")
    print(f"Recovered:  {recovered}")

This reproduces the worked example above exactly: HELLOILBDAHELLO, calling the identical enigma_transform function both times with the rotors reset to their starting positions, exactly the self-reciprocal property described above. Passing a plug_pairs dictionary like {'A': 'B', 'B': 'A'} adds plugboard swaps on top.

Limitations

This implementation covers the classic three-rotor military Enigma I described throughout this article, not the full historical family:

  • Ring settings are fixed at neutral, not implemented at all. As the Why the Rotors Are the Key Innovation section explains, this article fixes ring settings to their neutral value throughout for clarity. This code doesn’t expose a ring_setting parameter, so it can’t reproduce a message encrypted with a non-neutral ring setting.
  • Only Rotors I-III and Reflector B. Real Enigma machines could choose from more rotor options and a different reflector (Reflector A or C); this code hardcodes the three rotors and reflector used in the worked example above.
  • No four-rotor naval variant. As the article notes, four-rotor naval Enigma machines added complexity beyond what’s covered here; this code only implements the three-rotor configuration.
  • Not intended for real security. As the How Enigma Was Actually Broken section covers, the reflector’s fixed-point-free property and operational habits, not any flaw in this specific code, are what made real Enigma traffic breakable.

Conclusion

The Enigma machine represents the practical high-water mark of pre-computer cryptography covered anywhere in this series. It’s an electromechanical device that automated what Vigenère, Beaufort, and Autokey could only approximate by hand: a genuinely different substitution alphabet for nearly every keystroke, driven by physical rotors instead of a memorized keyword. Its combination of self-reciprocal operation, astronomical keyspace, and real deployed history make it a fitting capstone to this series’ journey through classical cryptography. Its ultimate defeat came through a combination of deep mathematical insight, purpose-built codebreaking machinery, and exploitation of real-world operational habits. That combination previews exactly the themes that define cryptography to this day: structural weaknesses hiding inside elegant designs, and the gap between theoretical and practical security.

FAQ

How does the Enigma machine work?

Pressing a key first advances the rightmost rotor, then sends an electrical signal through a plugboard, three rotors, a reflector, and back through the three rotors in reverse, before lighting a lamp showing the output letter. Because the rotors’ positions change with (almost) every keystroke, the effective substitution alphabet changes constantly.

Why can’t a letter ever encrypt to itself on Enigma?

Because the reflector’s wiring pairs up all 26 letters with no letter wired to itself. That’s a mathematical property (called having no fixed points) that guarantees the signal always takes a different path back than it took going in.

Is the Enigma machine self-reciprocal, like Beaufort?

Yes. Because the reflector makes the whole signal path an involution, running ciphertext back through the machine with the identical rotor and plugboard settings recovers the original plaintext exactly. There’s no separate encrypt/decrypt mode.

Who actually broke the Enigma cipher?

Polish mathematicians, led by Marian Rejewski, made the foundational breakthroughs in the 1930s. British codebreakers at Bletchley Park, notably Alan Turing, then built on and dramatically extended this work during World War II, using purpose-built machines like the Bombe alongside operational and procedural intelligence.

What is a “crib” in the context of breaking Enigma?

A crib is a known or strongly suspected fragment of plaintext believed to appear somewhere in an intercepted message, often from predictable message formats or routine phrases. Cribs, combined with Enigma’s “no letter encrypts to itself” property, let cryptanalysts rule out most possible message-crib alignments almost instantly.

References

  1. Wikipedia. “Enigma machine.” Available at: https://en.wikipedia.org/wiki/Enigma_machine

  2. Kahn, David. “The Codebreakers: The Story of Secret Writing.” Macmillan, 1967.

  3. Singh, Simon. “The Code Book.” Doubleday, 1999.

  4. Bletchley Park. “The Enigma Machine.” Available at: https://bletchleypark.org.uk/our-history/