Enigma
Enigma was the German cipher machine of the Second World War. This is an original model written from scratch for emulators.org, covering the three-rotor Enigma I of the Army and Air Force, the naval M3, and the four-rotor M4 of the U-boats: rotors I to VIII with Beta and Gamma, reflectors A, B, C and thin B and C, ring settings, the plugboard, and the stepping that makes the middle rotor move twice in a row.
You get the machine itself: keys that work by mouse or keyboard, lamps that stay lit while a key is held, rotors you can change and turn, and cables you can plug. A wiring diagram shows the path the current took for the last key. The main configurations set the machine to the real key of a wartime signal, with the settings shown so you can check them, and type the real cipher text. It comes out as the published decrypt: the sample in the 1930 manual, a signal from the invasion of the Soviet Union in 1941, the last signal from the Scharnhorst, and a U-264 signal first read in 2006. The debugger treats the rotor position as the program counter and one key press as a single step.
Runs on: Web browser
Enigma Online Emulator
Play Enigma using JavaScript directly in your browser.
Controls
Configurations
| Configuration | Emulator | Machine | OS | Legal | |
|---|---|---|---|---|---|
| Operation Barbarossa, 7 July 1941, part 1 | Enigma | Enigma I | open | Open ⛶ | |
| Operation Barbarossa, 7 July 1941, part 2 | Enigma | Enigma I | open | Open ⛶ | |
| Sample signal, 1930 Enigma manual | Enigma | Enigma I | open | Open ⛶ | |
| Enigma I, free to set | Enigma | Enigma I | open | Open ⛶ | |
| Double step: I II III at ADU | Enigma | Enigma I | open | Open ⛶ | |
| Last signal from the Scharnhorst, 26 December 1943 | Enigma | Enigma M3 | open | Open ⛶ | |
| Enigma M3, free to set | Enigma | Enigma M3 | open | Open ⛶ | |
| U-264 signal, 19 November 1942 | Enigma | Enigma M4 | open | Open ⛶ | |
| Enigma M4, free to set | Enigma | Enigma M4 | open | Open ⛶ |
Machines emulated
Notes
Embedding
The machine is written from scratch in plain JavaScript with no third-party code. enigma.js is the machine and enigma-panel.js draws it and takes input. The core runs on its own, including under Node:
var e = new Enigma({ model:'enigma-i', reflector:'B', wheels:['II','IV','V'],
rings:[2,21,12], start:'BLA', plugs:'AV BS CG DL FU HZ IN KM OW RX' });
e.type('EDPUDNRGYS'); // 'AUFKLXABTE'
e.press(0); // key A down: rotors step, returns the lamp
e.release(); // key up: lamp off
e.trace(0, e.currentPos()); // the path through the wheels, moving nothing
| Member | What it does |
|---|---|
model | 'enigma-i', 'm3' or 'm4'. Sets the wheels the panel offers. An M4 is four wheels with Beta or Gamma first and a thin reflector. |
rings | Letters ('AAAV') or 1-based numbers ([2,21,12]), left to right. |
start | The letters in the windows before the first key press. |
step() | One movement of the pawls and ratchets, with no signal. |
s, w(addr, v) | The state bytes, and the single write path that changes them. |
On the page, window.EMU_BOOT.mach is the machine and window.EMU_BOOT.app the panel.
Debugger integration
The debugger was built for CPUs and Enigma has none, so this is how the machine maps onto it. Registers, step, breakpoints and watchpoints are all real checks on the machine, but the words mean something a little different here.
- Registers are the rotor positions (
L.POSand so on, 00 = A), rings, the fitted wheels as a row of the wiring table, the key held, the lamp lit and the press count. The flagsR^andM^show the right and middle rotors standing at a notch. Writing to an editable register changes the machine. - The program counter is the rotor position as one number:
left × 676 + middle × 26 + right, with the Greek wheel × 17576 on an M4. Ordinary typing adds 1, so a turnover shows as a jump. With A = 0,ADUis 3 × 26 + 20 = $0062. - Single step is one key press. It presses the tape's next letter, or the key in
STEPKEYwhen there is no tape, and leaves the lamp lit so you can read it. There is no finer step: the rotors moving and the signal passing are one mechanical event here. The frame Step and the instruction Step do the same thing. - Execution breakpoints are rotor positions. The machine holds when the rotors arrive at that position, whichever key moved them, with the lamp for that press lit. The position has been reached and the letter enciphered by then, which is the one difference from a CPU, where a breakpoint stops before the instruction. Register conditions work on
L,M,R,G,POS,KEY,LAMPandCOUNT, soM == $04stops whenever the middle rotor reads E. - Watchpoints fire on any write to the machine state, including each rotor that the pawls actually move. A rotor that does not step is not written, so a write watchpoint on the left rotor's position fires only when it turns over. Addresses: reflector $01, wheels $02-05, rings $06-09, positions $0A-0D (Greek, left, middle, right), plugs $0E-27, lamp $28, key $29, press count $2A-2B. A change you make from the debugger itself does not trigger one. A read watchpoint never fires, because nothing reads this memory the way a CPU would: the wiring is not a bus.
- While held, the keys are locked. A real Enigma has no way to be paused, so this is the debugger's doing: Play releases them.
- Memory has four views. Machine state is the bytes above and can be written. Rotor positions lists every position with the next one it steps to (a
*marks a turnover) and the alphabet it would produce; click a row to set a breakpoint, and hover for the whole alphabet. Wiring tables is 26 bytes per wheel, in ASCII. The whole machine now is what each key would light at this position. The last three are worked out from the wiring and read without any side effect. - Devices shows the rotors with window, ring and core letter, the plug cables, and the signal path of the last key.
Architecture
The machine. A key closes a circuit from a battery through the plugboard, the entry wheel, the rotors from right to left, the reflector, back through the rotors from left to right, the plugboard again, and a lamp. The reflector makes the whole thing reciprocal, so the same settings encipher and decipher. It also means no letter can ever encipher to itself, which is the flaw that let codebreakers place a crib.
Ring settings. A rotor's alphabet ring and turnover notch turn together, around its wiring core. What the signal sees is the core position, which is the window letter minus the ring letter. The notch goes with the ring, so the turnover happens at a fixed window letter whatever the ring setting.
Stepping. The rotors move as the key goes down, before the signal flows. Three pawls ride on the ratchets. The right pawl always engages, the middle pawl only where the right rotor's notch is at the pawl, and the left pawl only where the middle rotor's notch is. The left pawl also pushes the middle rotor, which is what makes the middle rotor step twice in a row: ADU ADV AEW BFX BFY with rotors I, II, III. This model does exactly that and nothing extra, so the double step needs no special case in the code.
| Machine | Wheels | Reflector | Rings marked |
|---|---|---|---|
| Enigma I (Wehrmacht, Luftwaffe) | three of I-V | A, B, C | numbers 01-26 |
| Enigma M3 (Kriegsmarine) | three of I-VIII | B, C | letters |
| Enigma M4 (U-boats, from February 1942) | Beta or Gamma, then three of I-VIII | thin B, thin C | letters |
Rotors VI, VII and VIII have two notches, at Z and M. The Greek wheel has no ratchet and never steps, and an M4 with Beta at A and thin B is exactly an M3 with reflector B, which is what let it talk to three-rotor machines.
What was checked. Each configuration's cipher text goes through the keys here and has to come out as the published decrypt, letter for letter, and the page counts the agreement as it goes. These pass: the sample in the 1930 Enigma manual; both parts of the Operation Barbarossa message of 7 July 1941 (keys recovered by Geoff Sullivan and Frode Weierud); the Scharnhorst signal of 26 December 1943, intercepted by HMS Duke of York and thought to be her last; and the U-264 signal of 19 November 1942 from Stefan Krah's M4 Project. Also: AAAAA gives BDZGO, the double-step sequence above, and M4 with Beta and thin B, or Gamma and thin C, against M3 with B or C.
Not modelled. The Uhr switching box and the rewirable reflector D, the Abwehr and commercial machines, and the indicator procedures, which are operators' routines rather than parts of the machine. The panel lets you fit any wheel combination the machine's slots would accept, including ones a given day's rules forbade. The M4's plugboard sockets were numbered on the real machine and are lettered here. There is no sound.