""" enigma_configs.py This file contains the configuration details for some of the historical enigma machines. The configs are stored as dictionaries with the following keys: 'wheels' (aka rotors) A dictionary 'thin' (thin rotors) A dictionary (for 4 wheel enigmas) 'UKWs' (aka reflectors) A dictionary 'ETW' (aka QWERTZU) A 'Permutation' 'stecker' (True or False) Is there a stecker? 'dblstep' (True or False) Double stepping of middle rotors? 'UKWring' (True of False) Ring setting for UKW? 'UKWstep' (True of False) Does UKW step? Definitions Notch: Location of notch on the index ring. Turnover: Letter appearing in window when the notch is engaged with the stepping lever. UKW: Reflector or Umkehrwalze ETW: Entry wheel (stator) or Eintrittwalze Grund: Ground setting or Grundstellung Ringstellung: Ring setting Stecker: Plug Steckerbrett: Plugboard or Stecker board Walzen: Wheels Walzenlage: Wheel order Zusatzwalze: Griechenwalze or the thin (Greek) wheels Beta and Gamma Spruchschlussel: The message key Notes 1: Wheels Beta and Gamma have index rings but no notches. 2: Thin reflectors B and C are used only in the Model M-4 with Beta and Gamma wheels. 3: A self steckered character is a letter that is not 'switched' in the plugboard. 4: Thin (Greek) reflectors used with the M4 only. 5: Enigma-A, was used by the German Army and Air Force. The A models are fully compatible with an M3 Enigma, but only wheels I to V were supplied with the machine. Wheels VI to VIII were used exclusively by the German Navy. 6: The wiring for each of the wheels I - VIII can be set to one of 26 positions. 7: The Railway Enigma had a settable UKW and a ring setting on the UKW. """ from enigma import Rotor, Enigma, Permutation, identity # Abwehr G-260 setup. ------------------------------------- # Other names, Enigma G, 11-15-17 Machine # # Features: # Geared stepping (does not have the double stepping anomaly) # Does not have a Stecker panel # Settable UKW, UKW also has ring setting # UKW also rotates # ETW wiring was different # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # Frode Weierud (1997) # Abwehr_G260 = { 'wheels': {1 : Rotor("RCSPBLKQAUMHWYTIFZVGOJNEXD",turnover="ABCEFGIKLOPQSUVWZ"), # I 2 : Rotor("WCMIBVPJXAROSGNDLZKEYHUFQT",turnover="ACDFGHKMNQSTVYZ") , # II 3 : Rotor("FVDHZELSQMAXOKYIWPGCBUJTNR",turnover="AEFHKMNRUWX") }, # III 'thin': {}, 'UKWs': {'A': Rotor("IMETCGFRAYSQBZXWLHKDVUPOJN")}, 'ETW' : ~Permutation("QWERTZUIOASDFGHJKPYXCVBNML"), 'stecker': False, 'dblstep': False, 'UKWring': True, 'UKWstep': True, } # Abwehr G-312 setup. ------------------------------------- # Other names, Enigma G, 11-15-17 Machine # # Features: # Geared stepping (does not have the double stepping anomaly) # Does not have a Stecker panel # Settable UKW, UKW also has ring setting # UKW also rotates # ETW wiring was different # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # Dr. David H. Hamer (May 16 ,2004) # Data determined by measurement from Enigma G-312 # in the collection of the Bletchley Park Trust by # Dr. Hamer on October 20, 1998. # Abwehr_G312 = { 'wheels': {1 : Rotor("DMTWSILRUYQNKFEJCAZBPGXOHV",turnover="ABCEFGIKLOPQSUVWZ"), # I 2 : Rotor("HQZGPJTMOBLNCIFDYAWVEUSRKX",turnover="ACDFGHKMNQSTVYZ") , # II 3 : Rotor("UQNTLSZFMREHDPXKIBVYGJCWOA",turnover="AEFHKMNRUWX") }, # III 'thin': {}, 'UKWs': {'A': Rotor("RULQMZJSYGOCETKWDAHNBXPVIF")}, 'ETW' : ~Permutation("QWERTZUIOASDFGHJKPYXCVBNML"), 'stecker': False, 'dblstep': False, 'UKWring': True, 'UKWstep': True, } # The Enigma Commercial D setup. ------------------------------------- # # Features: # Double steps # Does not have a Stecker panel # Two UKW's (?) # ETW wiring was different # UKW was settable and had a ring setting # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer and Jim Oram (May 4, 2001) # Dr. David Hamer (June 10, 2004) # Commercial_D = { 'wheels': {1 : Rotor("LPGSZMHAEOQKVXRFYBUTNICJDW",turnover="Y"), # I 2 : Rotor("SLVGBTFXJQOHEWIRZYAMKPCNDU",turnover="E"), # II 3 : Rotor("CJGDPSHKTURAWZXFMYNQOBVLIE",turnover="N")}, # III 'thin': {}, 'UKWs': {'A': Rotor("IMETCGFRAYSQBZXWLHKDVUPOJN")}, 'ETW' : ~Permutation("QWERTZUIOASDFGHJKPYXCVBNML"), 'stecker': False, 'dblstep': True, 'UKWring': True, 'UKWstep': False, } # The Enigma Commercial K-470 setup. ---------------------- # # Features: # Double steps # Does not have a Stecker panel # Two UKW's # ETW wiring was different # UKW was settable and had a ring setting # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer and Jim Oram (May 4, 2001) # Dr. David Hamer (June 10, 2004) # # Looks identical to the Commercial D enigma, so I'm not going to bother # # --------------------------------------------------------- # Enigma Heer setup. -------------------------------------- # Other names: Enigma A, Heeres, Wehrmacht, Service Enigma, Army/GAF machine # # Features: # Double steps # Has a Stecker panel # Two UKW's # UKW was not settable # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer (1997) # Heer = { 'wheels': {1 : Rotor("EKMFLGDQVZNTOWYHXUSPAIBRCJ",turnover="Q"), # I 2 : Rotor("AJDKSIRUXBLHWTMCQGZNPYFVOE",turnover="E"), # II 3 : Rotor("BDFHJLCPRTXVZNYEIWGAKMUSQO",turnover="V"), # III 4 : Rotor("ESOVPZJAYQUIRHXLNFTGKDCMWB",turnover="J"), # IV 5 : Rotor("VZBRGITYUPSDNHLXAWMJQOFECK",turnover="Z")}, # V 'thin': {}, 'UKWs': {'A': Rotor("EJMZALYXVBWFCRQUONTSPIKHGD"), # UKW A was used prior to 1938 'B': Rotor("YRUHQSLDPXNGOKMIEBFZCWVJAT"), 'C': Rotor("FVPJIAOYEDRZXWGCTKUQSBNMHL")}, 'ETW' : identity, 'stecker': True, 'dblstep': True, 'UKWring': False, 'UKWstep': False, } # Enigma M3 setup. ---------------------------------------- # Other names, Service Enigma # # Features: # Double steps # Has a Stecker panel # Two UKW's # UKW was not settable # UKW did not rotate # # Source(s) # http://www.mlb.co.jp/linux/science/genigma/enigma-referat/node2.html (2004) # http://www.codesandciphers.org.uk/enigma/rotorspec.htm (2004) # Compiled by Tony Sale from the Enigma machines in the Bletchley Park Museum. # Compared to Enigma-E (2004) # M3 = { 'wheels': {1 : Rotor("EKMFLGDQVZNTOWYHXUSPAIBRCJ",turnover="Q"), # I 2 : Rotor("AJDKSIRUXBLHWTMCQGZNPYFVOE",turnover="E"), # II 3 : Rotor("BDFHJLCPRTXVZNYEIWGAKMUSQO",turnover="V"), # III 4 : Rotor("ESOVPZJAYQUIRHXLNFTGKDCMWB",turnover="J"), # IV 5 : Rotor("VZBRGITYUPSDNHLXAWMJQOFECK",turnover="Z"), # V 6 : Rotor("JPGVOUMFYQBENHZRDKASXLICTW",turnover="MZ"), # VI 7 : Rotor("NZJHGRCXMYSWBOUFAIVLPEKQDT",turnover="MZ"), # VII 8 : Rotor("FKQHTLXOCBJSPDZRAMEWNIUYGV",turnover="MZ")}, # VIII 'thin': {}, 'UKWs': {'B': Rotor("YRUHQSLDPXNGOKMIEBFZCWVJAT"), 'C': Rotor("FVPJIAOYEDRZXWGCTKUQSBNMHL")}, 'ETW' : identity, 'stecker': True, 'dblstep': True, 'UKWring': False, 'UKWstep': False, } # Enigma M4 setup. ---------------------------------------- # Other names, Service Enigma M4, Schlussel M # # Features: # Double steps # Has a Stecker panel # Two UKW's # UKW was not settable # UKW did not rotate # Fourth wheel chosen from a group of two (thin wheels 'beta' and 'gamma') # # Source(s) # http://www.mlb.co.jp/linux/science/genigma/enigma-referat/node2.html (2004) # http://www.codesandciphers.org.uk/enigma/rotorspec.htm (2004) # Compiled by Tony Sale from the Enigma machines in the Bletchley Park Museum. # Compared to Enigma-E (2004) # M4 = { 'wheels': {1 : Rotor("EKMFLGDQVZNTOWYHXUSPAIBRCJ",turnover="Q"), # I 2 : Rotor("AJDKSIRUXBLHWTMCQGZNPYFVOE",turnover="E"), # II 3 : Rotor("BDFHJLCPRTXVZNYEIWGAKMUSQO",turnover="V"), # III 4 : Rotor("ESOVPZJAYQUIRHXLNFTGKDCMWB",turnover="J"), # IV 5 : Rotor("VZBRGITYUPSDNHLXAWMJQOFECK",turnover="Z"), # V 6 : Rotor("JPGVOUMFYQBENHZRDKASXLICTW",turnover="MZ"), # VI 7 : Rotor("NZJHGRCXMYSWBOUFAIVLPEKQDT",turnover="MZ"), # VII 8 : Rotor("FKQHTLXOCBJSPDZRAMEWNIUYGV",turnover="MZ")}, # VIII 'thin': {'B' : Rotor("LEYJVCNIXWPBQMDRTAKZGFUHOS"), # beta 'C': Rotor("FSOKANUERHMBTIYCWLQPZXVGJD")}, # gamma 'UKWs': {'B': Rotor("ENKQAUYWJICOPBLMDXZVFTHRGS"), # thin B 'C': Rotor("RDOBJNTKVEHMLFCWZAXGYIPSUQ")}, # thin C 'ETW' : identity, 'stecker': True, 'dblstep': True, 'UKWring': False, 'UKWstep': False, } # Enigma Norway setup. ---------------------------------------- # The name Norway Enigma was coined by Frode Weierud. # # Features: # Double steps # Has a Stecker panel # Two UKW's # UKW was not settable # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer and Frode Weierud (2001) # Norway = { 'wheels': {1 : Rotor("WTOKASUYVRBXJHQCPZEFMDINLG",turnover="Q"), # I 2 : Rotor("GJLPUBSWEMCTQVHXAOFZDRKYNI",turnover="E"), # II 3 : Rotor("JWFMHNBPUSDYTIXVZGRQLAOEKC",turnover="V"), # III 4 : Rotor("FGZJMVXEPBWSHQTLIUDYKCNRAO",turnover="J"), # IV 5 : Rotor("HEJXQOTZBVFDASCILWPGYNMURK",turnover="Z")}, # V 'thin': {}, 'UKWs': {'A': Rotor("MOWJYPUXNDSRAIBFVLKZGQCHET")}, 'ETW' : identity, 'stecker': True, 'dblstep': True, 'UKWring': False, 'UKWstep': False, } # Enigma Polish setup. ---------------------------------------- # Other names: Polish Enigma Clone # # Features: # Double steps # Has a Stecker panel # Two UKW's # UKW was not settable # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer, Frode Weierud # Polish = { 'wheels': {1 : Rotor("EKMFLGDQVZNTOWYHXUSPAIBRCJ",turnover="Q"), # I 2 : Rotor("AJDKSIRUXBLHWTMCQGZNPYFVOE",turnover="E"), # II 3 : Rotor("BDFHJLCPRTXVZNYEIWGAKMUSQO",turnover="V"), # III 4 : Rotor("ESOVPZJAYQUIRHXLNFTGKDCMWB",turnover="J"), # IV 5 : Rotor("VZBRGITYUPSDNHLXAWMJQOFECK",turnover="Z")}, # V 'thin': {}, 'UKWs': {'A': Rotor("EJMZALYXVBWFCRQUONTSPIKHGD"), 'B': Rotor("YRUHQSLDPXNGOKMIEBFZCWVJAT")}, 'ETW' : identity, 'stecker': True, 'dblstep': True, 'UKWring': False, 'UKWstep': False, } # Enigma Railway setup. ---------------------------------------- # # Features: # Double steps # UKW was settable # UKW had a ring setting # UKW did not rotate # ETW was wired differently # # Source(s) # CSG Railway Enigma Simulator (2004) # Railway = { 'wheels': {1 : Rotor("JGDQOXUSCAMIFRVTPNEWKBLZYH",turnover="N"), # I 2 : Rotor("NTZPSFBOKMWRCJDIVLAEYUXHGQ",turnover="E"), # II 3 : Rotor("JVIUBHTCDYAKEQZPOSGXNRMWFL",turnover="Y")}, # III 'thin': {}, 'UKWs': {'A': Rotor("QYHOGNECVPUZTFDJAXWMKISRBL")}, 'ETW' : ~Permutation("QWERTZUIOASDFGHJKPYXCVBNML"), 'stecker': False, 'dblstep': True, 'UKWring': True, 'UKWstep': False, } # The Enigma Swiss K setup. ---------------------------------------- # (Swiss Air Force Enigma Example) # # Features: # Double steps # Does not have a Stecker panel # One UKW's # ETW wiring was different # UKW was settable and had a ring setting # UKW did not rotate # # Source(s) # Paul Reuvers Risc OS Enigma Simulator (2004) # David Hamer and Jim Oram (May 4, 2001) # Swiss_K = { 'wheels': {1 : Rotor("PEZUOHXSCVFMTBGLRINQJWAYDK",turnover="Y"), # I 2 : Rotor("ZOUESYDKFWPCIQXHMVBLGNJRAT",turnover="E"), # II 3 : Rotor("EHRVXGAOBQUSIMZFLYNWKTPDJC",turnover="N")}, # III 'thin': {}, 'UKWs': {'A': Rotor("IMETCGFRAYSQBZXWLHKDVUPOJN")}, 'ETW' : ~Permutation("QWERTZUIOASDFGHJKPYXCVBNML"), 'stecker': False, 'dblstep': True, 'UKWring': True, 'UKWstep': False, } # Enigma Tirpitz setup. ---------------------------------------- # # Features: # Double steps # Does not have a Stecker panel # UKW was settable # UKW had a ring setting # UKW did not rotate # ETW was wired differently # # Source(s) # http://www.eclipse.net/~dhamer/download.htm (2004) # Enigma Variations: An Extended Family of Machines (1998) # Dr. David H. Hamer, Geoff Sullivan, and Frode Weierud # Paul Reuvers, Risc OS Enigma simulator (2004) # David Hamer, NCM; Tony Sale, BP; Frode Weierud, NCM; # Philip Marks, NARA records. (1997) # Tirpitz = { 'wheels': {1 : Rotor("KPTYUELOCVGRFQDANJMBSWHZXI",turnover="EKQWZ"), # I 2 : Rotor("UPHZLWEQMTDJXCAKSOIGVBYFNR",turnover="FLRWZ"), # II 3 : Rotor("QUDLYRFEKONVZAXWHMGPJBSICT",turnover="EKQWZ"), # III 4 : Rotor("CIWTBKXNRESPFLYDAGVHQUOJZM",turnover="FLRWZ"), # IV 5 : Rotor("UAXGISNJBVERDYLFZWTPCKOHMQ",turnover="CFKRY"), # V 6 : Rotor("XFUZGALVHCNYSEWQTDMRBKPIOJ",turnover="EIMQX"), # VI 7 : Rotor("BJVFTXPLNAYOZIKWGDQERUCHSM",turnover="CFKRY"), # VII 8 : Rotor("YMTPNZHWKODAJXELUQVGCBISFR",turnover="EIMQX")}, # VIII 'thin': {}, 'UKWs': {'A': Rotor("GEKPBTAUMOCNILJDXZYFHWVQSR")}, 'ETW' : ~Permutation("KZROUQHYAIGBLWVSTDXFPNMCJE"), 'stecker': False, 'dblstep': True, 'UKWring': True, 'UKWstep': False, } # ------- end configurations ------------------------------ """ Sending a message (M3) Basic settings (Wheel order, Rings, Stecker, and starting position) were written down in a code book, and changed daily. Different parts of the army used different code books. Then operator selects 3 letters at random (e.g. AGI) and typed it twice (e.g. AGIAGI). Sending it twice was done to avoid any transmission errors, if letters have been lost. The random selection of the message key should prevent any statistical analysis on the data, but offers possibility for human errors. The actual message was coded with this message key( e.g.AGI ). Here is an example : 1. Setup wheel - 213 wheels used and their order ring - ZWD ring settings for wheels in order grund - FRX starting positions of the wheels stecker - ezblxpwriuvmjo list of letters that were switched on the stecker board type the plain text message key - (AGIAGI) output - HCALNU 2. Setup wheel - 213 wheels used and their order ring - ZWD ring settings for wheels in order grund - AGI starting positions of the wheels stecker - ezblxpwriuvmjo list of letters that were switched on the stecker board type plain text of message - AUFB EFEHL DESOB ERSTE NBEFE HLSHA BERSS INDIM FALLE XZXZT XUNWA HRSCH EINLI CHENX FRANZ OESIS QENAN GRIFF SDIEW ESTBE FESTI GUNGE NJEDE RZAHL ENMAE SSIGE NUEBE RLEGE NHEIT ZUMTR OTZZU HALTE NX output QKRQ WUQTZ KFXZO MJFOY RHYZW VBXYS IWMMV WBLEB DMWUW BTVHM RFLKS DCCEX IYPAH RMPZI OVBBR VLNHZ UPOSY EIPWJ TUGYO SLAOX RHKVC HQOSV DTRBP DJEUK SBBXH TYGVH GFICA CVGUV OQFAQ WBKXZ JSQJF ZPEVJ RO 3. The output was sent: At the beginning was some plain text (date, time, number of letters...) The first 6 letters are the enciphered message key, written twice. + HRKM 13617 1807 - AN HEERESGRUPPENKOMMANDO 2= 2109 -1750 - 3 TLE - FRX FRX - 1TL -172= HCALN UQKRQ AXPWT WUQTZ KFXZO MJFOY RHYZW VBXYS IWMMV WBLEB DMWUW BTVHM RFLKS DCCEX IYPAH RMPZI OVBBR VLNHZ UPOSY EIPWJ TUGYO SLAOX RHKVC HQOSV DTRBP DJEUK SBBXH TYGVH GFICA CVGUV OQFAQ WBKXZ JSQJF ZPEVJ RO Note : AXPWT was an identifier key added to the message. Deciphering Deciphering of the text was done in reverse way. Security A message should not be longer than 200 characters. Longer messages were split up into pieces with different keys. The letter combination CH was abbreviated (abgekurtzt) by Q, words have been separated by X. Numbers have to be spelled out. """ if __name__ == '__main__': # Let's check it out with the example. EM3 = Enigma(M3,wheels=213,UKW='b',ringstellung='zwd',grundstellung='frx',stecker='ezblxpwriuvmjo') print print "Our machine configuration is:" print "Enigma(M3,wheels=213,UKW='b',ringstellung='zwd',grundstellung='frx',stecker='ezblxpwriuvmjo')" print print "The indicator is AGI. Doubled and enciphered it is:" print EM3('agiagi') EM3.setKeys('frx') print "We'll decode HCALNU to double check." print EM3('hcalnu') print print "Now we'll use the setting AGI to encipher:" print print 'AUFB EFEHL DESOB ERSTE NBEFE HLSHA BERSS INDIM FALLE XZXZT' print 'XUNWA HRSCH EINLI CHENX FRANZ OESIS QENAN GRIFF SDIEW ESTBE' print 'FESTI GUNGE NJEDE RZAHL ENMAE SSIGE NUEBE RLEGE NHEIT ZUMTR' print 'OTZZU HALTE NX' EM3.setKeys('agi') print print "We get:" print print EM3('AUFB EFEHL DESOB ERSTE NBEFE HLSHA BERSS INDIM FALLE XZXZT') print EM3('XUNWA HRSCH EINLI CHENX FRANZ OESIS QENAN GRIFF SDIEW ESTBE') print EM3('FESTI GUNGE NJEDE RZAHL ENMAE SSIGE NUEBE RLEGE NHEIT ZUMTR') print EM3('OTZZU HALTE NX') print print "The text above should match the text below." print print 'QKRQ WUQTZ KFXZO MJFOY RHYZW VBXYS IWMMV WBLEB DMWUW BTVHM' print 'RFLKS DCCEX IYPAH RMPZI OVBBR VLNHZ UPOSY EIPWJ TUGYO SLAOX' print 'RHKVC HQOSV DTRBP DJEUK SBBXH TYGVH GFICA CVGUV OQFAQ WBKXZ' print 'JSQJF ZPEVJ RO' # ------- end enigma_configs.py ---------------------------