Skip to content
All tools
Classical cryptoRuns locallyNo account

Enigma machine simulator and cracker

Run Enigma I, M3 and the four-rotor M4 in the browser, and recover the rotor order and start positions of an unplugged machine by brute force.

Open in ctfpal

Enigma is a rotor machine: each keypress sends a current through a plugboard, three or four rotating wired drums, a reflector, and back out through the drums and plugboard again. Because the rotors advance between letters, the same plaintext letter encrypts differently every time - and because the reflector pairs letters up, the machine is its own inverse. Encrypting the ciphertext on the same settings gives the plaintext back.

The settings you need

  • Rotor order (Walzenlage) - which drums are fitted and in what order, written left to right as they sit in the machine. Three from a set of five for the army and air force; the navy had eight.
  • Ring setting (Ringstellung) - how far the wiring is rotated relative to the letter ring. It changes the substitution without changing when a rotor steps, because the notch is cut in the ring.
  • Rotor position (Grundstellung) - the letters showing in the windows when you start.
  • Plugboard (Steckerbrett) - up to thirteen cables swapping letters in pairs, before and after the rotors. This is where most of Enigma's key space lived.

The two properties every attack rests on

No letter ever encrypts to itself. The reflector is a fixed-point-free pairing, so the current can never come back out of the contact it went in on. That single fact is what the Bombe was built around: slide a crib along the ciphertext, and every alignment where a letter would have to encrypt to itself is impossible, whatever the key is. It costs one comparison per position and throws away most of the search space before any machine is run.

The other property is the double step. The middle rotor advances when the right rotor passes its notch - and also on the very next keypress after it reaches its own, dragging the left rotor with it. It is a quirk of the pawl mechanism rather than a design decision, and it is where simulators go wrong. A machine that treats the rotors as an odometer produces correct output for the first twenty-odd letters and confident nonsense after that, which is worse than failing outright.

Breaking one in a CTF

Without a plugboard, Enigma is brute-forceable: sixty rotor orders times 17,576 start positions is about a million machines, and the index of coincidence of the output separates the right one from the rest. That is what the cracker here does. With a plugboard it is not - a wrongly-decrypted message looks statistically identical to a rightly-decrypted one until the plugs are also right, which is precisely why the Bombe existed and why this is not one. Most CTF Enigma challenges leave the plugboard empty or hand you the settings and expect you to run the machine.

Ring settings are handled in two stages, the way they historically were. The left and middle rings have no visible effect until their rotor steps, so for a short message only the right-hand ring matters - and once the positions are known, sliding the right ring and the right window together by the same amount leaves the substitution alone while moving the notch. Exactly one of the twenty-six pairs keeps the message readable past the point where the middle rotor steps.