I have come across Lockheed Martin's problem from the 2018 CodeQuest, a numeric Enigma machine:
I am wondering what the best way to code the rotors and their mappings is, considering that "rotation" needs to be applied- similar to how an odometer works.
My first supposition was using lists/arrays:
For instance, if I use rotors 1,2,3 all initially set to their 0 position (as depicted), and if I want to encrypt the message 1234567890. I know, as a test case, that the output should be 4805344463. I do get the first digit encrypted correctly, to 4. However, then the rightmost rotor (rotor 3 in this case) must "shift down one position." I used slicing to shift the arrays:
This has lead me to believe that, perhaps, using the rotor config/mappings as I have laid them out won't work.
Is anyone familiar with this problem? Can anyone offer me any help or advice on this?
I am wondering what the best way to code the rotors and their mappings is, considering that "rotation" needs to be applied- similar to how an odometer works.
My first supposition was using lists/arrays:
rotor1 = [1, 3, 6, 0, 5, 4, 8, 7, 9, 2] rotor2 = [0, 3, 5, 2, 6, 9, 1, 4, 8, 7] rotor3 = [5, 9, 1, 7, 3, 8, 0, 2, 4, 6] rotor4 = [1, 6, 5, 2, 9, 0, 7, 4, 3, 8]In this setup, the index value represents the input side of the rotor and the value represents the output side of the rotor. So, if you want to input 1 into rotor 1, you would get an output of 3. This works okay, if the rotors are all in position 0, as depicted. However, once rotation comes into play, this doesn't seem to work anymore.
For instance, if I use rotors 1,2,3 all initially set to their 0 position (as depicted), and if I want to encrypt the message 1234567890. I know, as a test case, that the output should be 4805344463. I do get the first digit encrypted correctly, to 4. However, then the rightmost rotor (rotor 3 in this case) must "shift down one position." I used slicing to shift the arrays:
shifted_rotor = rotor[1:] + rotor[:1]I have also tried going in the other direction:
shifted_rotor = rotor[-1:] + rotor[:-1]However, after applying the aforementioned shift, in either direction, and then attempting to encrypt the next digit in the message sequence, which would be 2, I don't get 8, as I should get.
This has lead me to believe that, perhaps, using the rotor config/mappings as I have laid them out won't work.
Is anyone familiar with this problem? Can anyone offer me any help or advice on this?