A golang implementation of a German Wehrmacht (Army) Enigma
I, which was used to encrypt German radio messages
during World War 2.
The Enigma encryption was cracked by a team of Allied cryptographers at Bletchly Park, notably including Alan Turing. The machines they built to break Enigma arguably kick-started the field of computer science.
go install github.com/rjhacks/enigmaOr decrypt a real-life message from the Enigma I manual!
$GOPATH/bin/enigma crypt \
--reflector=A \
--rotors=II,I,III \
--ringSettings=24,13,22 \
--plugPairs=AM,FI,NV,PS,TU,WZ \
--positions=A,B,L \
GCDSE AHUGW TQGRK VLFGX UCALX VYMIG MMNMF DXTGN VHVRM MEVOU YFZSL RHDRR XFJWC FHUHM UNZEF RDISI KBGPM YVXUZIf you'd like to play with the Enigma in code, you can include it directly in your programs. See
enigma/enigma_test.go for examples.
This implementation of the Enigma aims to be true to the Enigma I, as it was in December 1938. The defining characteristics of this model include:
- Three rotors (although the core code actually supports any number of rotors), chosen from a set of
five rotors,
IthroughV. - A single turnover point per rotor.
- A straight connection on the entry stator (AKA: entry wheel, Eintrittswalze, ETW). Straight means
that
Amaps toA,Bmaps toB, and so forth. - No "Uhr", a possible extension of the plugboard.
There is a wealth of information about the Enigma on the internet, thanks to its historic status. Some pages that were particularly helpful in building the understanding of Engima for this implementation were:
- Wikipedia for its comprehensive overview and its rotor details.
- Franklin Heath for its sample messages.
- The Crypto Museum, for its wiring schematics and clear type-by-type details.
Despite these excellent sources, there is conflicting information about whether the rotors rotate before or after the electrical contact for a letter is made. Based on example encryptions, the correct answer here is that the rotors rotate before the contact is made.
