Ciphers

Enigma M3

The Wehrmacht machine with rotors I, II, III and reflector B. Rotor positions, ring settings, a plugboard. Reciprocal, so one setting works both ways.
IDenigma38 / 72classical · rotor
Cipher / Rotor

Enigma M3

Wehrmacht M3, rotors I II III, reflector B.

Keyspace
26^6 × plugboard configurations
Decode
self-inverse
Works on
A-Z, the rest passes
Family
1 in rotor
required 0 / 3

Options

positionsstring
default AAA
Initial rotor positions, left to right
ringsstring
default AAA
Ring settings, left to right
plugboardstring
optional
Space-separated letter pairs, for example "AV BS CG"

Access

Createcreate("enigma")
CLIciphers encode enigma 'ATTACK AT DAWN' --positions MCK --rings BDF --plugboard 'AV BS CG'
Tryplayground with the sample above

One fixed machine: rotors I, II and III in that order from left to right, reflector B, double step of the middle rotor included. Three settings are yours. positions is the three letters in the windows at the start, rings the ring settings, both default AAA. plugboard is up to thirteen letter pairs separated by spaces. Enigma is reciprocal, so decode is encode with the same settings. Only A to Z go through the machine and step the rotors, anything else passes through untouched.

ts
const enigma = create("enigma");
enigma.encode("AAAAA").text; // "BDZGO", the standard test vector
enigma.encode("AAA", { positions: "ADU" }).text; // "EQI", a double-step vector
const settings = { positions: "MCK", rings: "BDF", plugboard: "AV BS CG DL FU HZ IN KM OW RX" };
enigma.encode("SECRETMESSAGE", settings).text; // "KILYLYNVKOEPS"
enigma.decode("KILYLYNVKOEPS", settings).text; // "SECRETMESSAGE"

A letter in two plugboard pairs, a position that isn't three letters, a ring setting with a digit - each is an InvalidOptionError before the machine turns. And the machine never maps a letter to itself. That was its famous flaw, and it's the reason a known plaintext could be slid along a ciphertext at Bletchley.