After all this time, this is kind of a cop out, but one with a solution.
I certainly did learn a lot about the enigma machine during the process.
As it turns out, there was already an enigma cipher/decipher algorithm available.
So here's a synopsis on how to use it:
This returns the proper code 'GVYWHF' for 'ENIGMA'
when
window = 'Q', 'u', 'O' (left to rih=ght)
rotors = V, III, and I (left to right)
plugboard = M <--> Z and N <--> S
Rings set to 12, 4, 8 ('L', 'D', 'H')
Reflector = 'B'
import pycipher
import string
def num_to_letter(nums):
"""
Convert number of alphabet to characters
:param nums: list of numbers, 1 based
:return: list of letters
"""
alpha = string.ascii_uppercase
alst = []
for num in nums:
alst.append(alpha[num - 1])
return alst
def letter_to_num(letters):
"""
Convert letters of alphabet to numbers
:param letters: list of letters
:return: list of numbers, 1 based
"""
alpha = string.ascii_uppercase
nlst = [ ]
for letter in letters:
nlst.append(alpha.index(letter) + 1)
return nlst
if __name__ == '__main__':
se = pycip = pycipher.Enigma(settings=('Q', 'U', 'O'),
rotors=(5, 3, 1),
reflector='B',
ringstellung=('L', 'D', 'H'),
steckers=[('M', 'Z'), ('N', 'S')])
print(se.encipher('ENIGMA'))
se.reset_settings()
print(se.encipher('GVYWHF'))
Results:
Output:
GVYWHF
ENIGMA