1def plugboard(text, list_of_sets):
2 converted_str = ""
3 for character in text:
4 new_char = character
5 for s in list_of_sets:
6 if character in s:
7 new_char = (s - {character}).pop()
8 break
9 converted_str += new_char
10 return converted_str
11
12def rotor(text, dictionary):
13 converted_str = ""
14 for character in text:
15 converted_str += dictionary[character]
16 return converted_str
17
18def enigma_encrypt(plugboard_position, rotor_position):
19 def decorator(func):
20 def encrypt(text):
21 text = plugboard(text, plugboard_position)
22 text = rotor(text, rotor_position)
23 return func(text)
24 return encrypt
25 return decorator
26
27def enigma_decrypt(plugboard_position, rotor_position):
28 def decorator(func):
29 def decrypt(text):
30 text = rotor(text, {val: key for key, val in rotor_position.items()})
31 text = plugboard(text, plugboard_position)
32 return func(text)
33 return decrypt
34 return decorator
E.EE....E
======================================================================
ERROR: test_full_letter_set (test.TestCombination)
Test decrypting an encrypted text against itself.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 139, in test_full_letter_set
self.assertEqual(combined('i love python'), 'i love python')
File "/tmp/solution.py", line 30, in decrypt
text = rotor(text, {val: key for key, val in rotor_position.items()})
File "/tmp/solution.py", line 15, in rotor
converted_str += dictionary[character]
KeyError: ' '
======================================================================
ERROR: test_full_letter_set (test.TestDecryptor)
Test the decryptor function with all letters in the rotor.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 112, in test_full_letter_set
self.assertEqual(decrypted('mlx fuver cbakn jad guoyq aixb mlx pzhw sat'),
File "/tmp/solution.py", line 30, in decrypt
text = rotor(text, {val: key for key, val in rotor_position.items()})
File "/tmp/solution.py", line 15, in rotor
converted_str += dictionary[character]
KeyError: ' '
======================================================================
ERROR: test_full_letter_set (test.TestEncryptor)
Test the encryptor function with all letters in the rotor.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 89, in test_full_letter_set
self.assertEqual(encrypted('the quick brown fox jumps over the lazy dog'),
File "/tmp/solution.py", line 22, in encrypt
text = rotor(text, rotor_position)
File "/tmp/solution.py", line 15, in rotor
converted_str += dictionary[character]
KeyError: ' '
======================================================================
ERROR: test_normal_case (test.TestRotor)
Test the rotor function with normally expected input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 67, in test_normal_case
self.assertEqual(rotor('this is a test input', self.ROTOR_POSITION), 'kbjo jo c kdok jylqk')
File "/tmp/solution.py", line 15, in rotor
converted_str += dictionary[character]
KeyError: ' '
----------------------------------------------------------------------
Ran 9 tests in 0.001s
FAILED (errors=4)
30.10.2023 09:49