# Enigma Ring Settings

a guest
Jun 15th, 2019
1,017
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. def get_index(letter, alphabet):
2.         '''Get index of letter in alphabet'''
3.         for i in range(0, len(alphabet)):
4.             if alphabet[i] == letter:
5.                 return i
6.
7.
8. def shift(letter, shift, alphabet):
9.         '''Shift letter up/down in the alphabet by given shift'''
10.         for i in range(0, len(alphabet)):
11.             if alphabet[i] == letter:
12.                 return alphabet[(i + shift) % len(alphabet)]
13.
14.
15. import sys
16.
17. print("################################################\n\n")
18. # Alphabet variable
19. alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
20. # Set ringstellung
21. ringstellung = get_index(sys.argv[1].upper(), alphabet)
22. print("Ringstellung: " + str(ringstellung))
23. # Set wiring variable
24. wiring = "EKMFLGDQVZNTOWYHXUSPAIBRCJ"
25. # Set dot position to postion of A in current wiring
26. dot_position = get_index("A", wiring)
27. print("Dot position: " + str(dot_position))
28. # Loop over all letters before ringstellung (in the alpabet); e.g.: ringstellung 5: loop: 0, 1, 2, 3, 4
29. for i in range(0, ringstellung):
30.     # Set temporary wiring variable
31.     temp_wiring = wiring
32.     # Set acutall wiring to empty string
33.     wiring = ""
34.     # Loop over chars in temporary wiring
35.     for char in temp_wiring:
36.         # Shift the char by one and add that shiftet char to wiring variable
37.         wiring += shift(char, 1, alphabet)
38.     # Add one to dot position, make sure we don't exceed the lenght of the alphabet
39.     dot_position = (dot_position + 1) % len(alphabet)
40.     print("Wiring shiftet up the alphabet: " + wiring)
41.     print("New dot position: " + str(dot_position))
42. i = 0;
43. # While the letter at the dot position doesn't match with the ringstellung
44. while not wiring[dot_position] == alphabet[ringstellung]:
45.     i += 1;
46.     # Rotate the wiring
47.     wiring = wiring[-1:] + wiring[:-1]
48.     print("Rotation " + str(i).zfill(2) + "; Wiring: " + wiring)
49.
50. print("--------------------------------------")
51. print("Ringstellung: " + alphabet[ringstellung])
52. print("Final mapping:")
53. print(alphabet)
54. print("↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓")
55. print(wiring)
56. print("--------------------------------------")
57. print("################################################\n\n")