Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Numeric Enigma Machine
#1
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:

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?
Reply


Messages In This Thread
Numeric Enigma Machine - by idev - Mar-27-2024, 09:50 PM
RE: Numeric Enigma Machine - by bowlofred - Mar-27-2024, 10:52 PM
RE: Numeric Enigma Machine - by idev - Mar-28-2024, 01:54 AM
RE: Numeric Enigma Machine - by idev - Mar-28-2024, 03:38 AM
RE: Numeric Enigma Machine - by bowlofred - Mar-28-2024, 04:44 AM
RE: Numeric Enigma Machine - by idev - Mar-28-2024, 01:30 PM
RE: Numeric Enigma Machine - by bowlofred - Mar-28-2024, 06:07 AM
RE: Numeric Enigma Machine - by idev - Mar-28-2024, 12:45 PM
RE: Numeric Enigma Machine - by idev - Mar-28-2024, 02:17 PM
RE: Numeric Enigma Machine - by idev - Mar-29-2024, 06:15 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Enigma Decoding Problem krisarmstrong 4 851 Dec-14-2023, 10:42 AM
Last Post: Larz60+
Question Numeric Anagrams - Count Occurances monty024 2 1,550 Nov-13-2021, 05:05 PM
Last Post: monty024
  How to get datetime from numeric format field klllmmm 3 2,055 Nov-06-2021, 03:26 PM
Last Post: snippsat
  Extract continuous numeric characters from a string in Python Robotguy 2 2,702 Jan-16-2021, 12:44 AM
Last Post: snippsat
  How to calculate column mean and row skip non numeric and na Mekala 5 5,053 May-06-2020, 10:52 AM
Last Post: anbu23
  Alpha numeric element list search rhubarbpieguy 1 1,830 Apr-01-2020, 12:41 PM
Last Post: pyzyx3qwerty
  convert a character to numeric and back Skaperen 2 2,163 Jan-28-2020, 09:32 PM
Last Post: Skaperen
  are numeric types passed by value or reference? rudihammad 4 2,683 Nov-19-2019, 06:25 AM
Last Post: rudihammad
  'Age' categorical (years -months -days ) to numeric Smiling29 4 2,992 Oct-17-2019, 05:26 PM
Last Post: Smiling29
  how to do a numeric sort Skaperen 11 5,077 Jul-12-2019, 09:50 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020