1def plugboard(word, translator):
2 plug_dict = {}
3 for pair in translator:
4 char1, char2 = pair
5 plug_dict[char1] = char2
6 plug_dict[char2] = char1
7 return ''.join(plug_dict.get(letter, letter) for letter in word)
8
9def rotor(word, translator):
10 return ''.join(translator.get(letter) for letter in word)
11
12def enigma_encrypt(plugboard_position, rotor_position):
13 def decorator(func):
14 def wrapper(text):
15 encrypted_text = plugboard(text, plugboard_position)
16 encrypted_text = rotor(encrypted_text, rotor_position)
17 return func(encrypted_text)
18 return wrapper
19 return decorator
20
21def enigma_decrypt(plugboard_position, rotor_position):
22 def decorator(func):
23 def wrapper(text):
24 rotor_position_copy = {value: key for key, value in rotor_position.items()}
25 decrypted_word = rotor(text, rotor_position_copy)
26 decrypted_word = plugboard(decrypted_word, plugboard_position)
27 return func(decrypted_word)
28 return wrapper
29 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 25, in wrapper
decrypted_word = rotor(text, rotor_position_copy)
File "/tmp/solution.py", line 10, in rotor
return ''.join(translator.get(letter) for letter in word)
TypeError: sequence item 1: expected str instance, NoneType found
======================================================================
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 25, in wrapper
decrypted_word = rotor(text, rotor_position_copy)
File "/tmp/solution.py", line 10, in rotor
return ''.join(translator.get(letter) for letter in word)
TypeError: sequence item 3: expected str instance, NoneType found
======================================================================
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 16, in wrapper
encrypted_text = rotor(encrypted_text, rotor_position)
File "/tmp/solution.py", line 10, in rotor
return ''.join(translator.get(letter) for letter in word)
TypeError: sequence item 3: expected str instance, NoneType found
======================================================================
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 10, in rotor
return ''.join(translator.get(letter) for letter in word)
TypeError: sequence item 4: expected str instance, NoneType found
----------------------------------------------------------------------
Ran 9 tests in 0.001s
FAILED (errors=4)
f | 1 | def plugboard(word, translator): | f | 1 | def plugboard(word, translator): |
2 | plug_dict = {} | 2 | plug_dict = {} | ||
3 | for pair in translator: | 3 | for pair in translator: | ||
4 | char1, char2 = pair | 4 | char1, char2 = pair | ||
5 | plug_dict[char1] = char2 | 5 | plug_dict[char1] = char2 | ||
6 | plug_dict[char2] = char1 | 6 | plug_dict[char2] = char1 | ||
7 | return ''.join(plug_dict.get(letter, letter) for letter in word) | 7 | return ''.join(plug_dict.get(letter, letter) for letter in word) | ||
8 | 8 | ||||
9 | def rotor(word, translator): | 9 | def rotor(word, translator): | ||
10 | return ''.join(translator.get(letter) for letter in word) | 10 | return ''.join(translator.get(letter) for letter in word) | ||
11 | 11 | ||||
12 | def enigma_encrypt(plugboard_position, rotor_position): | 12 | def enigma_encrypt(plugboard_position, rotor_position): | ||
13 | def decorator(func): | 13 | def decorator(func): | ||
14 | def wrapper(text): | 14 | def wrapper(text): | ||
15 | encrypted_text = plugboard(text, plugboard_position) | 15 | encrypted_text = plugboard(text, plugboard_position) | ||
16 | encrypted_text = rotor(encrypted_text, rotor_position) | 16 | encrypted_text = rotor(encrypted_text, rotor_position) | ||
17 | return func(encrypted_text) | 17 | return func(encrypted_text) | ||
18 | return wrapper | 18 | return wrapper | ||
19 | return decorator | 19 | return decorator | ||
20 | 20 | ||||
21 | def enigma_decrypt(plugboard_position, rotor_position): | 21 | def enigma_decrypt(plugboard_position, rotor_position): | ||
22 | def decorator(func): | 22 | def decorator(func): | ||
23 | def wrapper(text): | 23 | def wrapper(text): | ||
n | 24 | rotor_position_copy = rotor_position.copy() | n | ||
25 | rotor_position_copy = {value: key for key, value in rotor_position.items()} | 24 | rotor_position_copy = {value: key for key, value in rotor_position.items()} | ||
t | 26 | #без да правя копие ми хвърля грешка, че не мога да access-на rotor_position | t | ||
27 | decrypted_word = rotor(text, rotor_position_copy) | 25 | decrypted_word = rotor(text, rotor_position_copy) | ||
28 | decrypted_word = plugboard(decrypted_word, plugboard_position) | 26 | decrypted_word = plugboard(decrypted_word, plugboard_position) | ||
29 | return func(decrypted_word) | 27 | return func(decrypted_word) | ||
30 | return wrapper | 28 | return wrapper | ||
31 | return decorator | 29 | return decorator |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def plugboard(word, translator): | f | 1 | def plugboard(word, translator): |
2 | plug_dict = {} | 2 | plug_dict = {} | ||
3 | for pair in translator: | 3 | for pair in translator: | ||
4 | char1, char2 = pair | 4 | char1, char2 = pair | ||
5 | plug_dict[char1] = char2 | 5 | plug_dict[char1] = char2 | ||
6 | plug_dict[char2] = char1 | 6 | plug_dict[char2] = char1 | ||
7 | return ''.join(plug_dict.get(letter, letter) for letter in word) | 7 | return ''.join(plug_dict.get(letter, letter) for letter in word) | ||
8 | 8 | ||||
9 | def rotor(word, translator): | 9 | def rotor(word, translator): | ||
10 | return ''.join(translator.get(letter) for letter in word) | 10 | return ''.join(translator.get(letter) for letter in word) | ||
11 | 11 | ||||
12 | def enigma_encrypt(plugboard_position, rotor_position): | 12 | def enigma_encrypt(plugboard_position, rotor_position): | ||
13 | def decorator(func): | 13 | def decorator(func): | ||
t | 14 | def wrapper(str): | t | 14 | def wrapper(text): |
15 | encrypted_text = plugboard(str, plugboard_position) | 15 | encrypted_text = plugboard(text, plugboard_position) | ||
16 | encrypted_text = rotor(encrypted_text, rotor_position) | 16 | encrypted_text = rotor(encrypted_text, rotor_position) | ||
17 | return func(encrypted_text) | 17 | return func(encrypted_text) | ||
18 | return wrapper | 18 | return wrapper | ||
19 | return decorator | 19 | return decorator | ||
20 | 20 | ||||
21 | def enigma_decrypt(plugboard_position, rotor_position): | 21 | def enigma_decrypt(plugboard_position, rotor_position): | ||
22 | def decorator(func): | 22 | def decorator(func): | ||
23 | def wrapper(text): | 23 | def wrapper(text): | ||
24 | rotor_position_copy = rotor_position.copy() | 24 | rotor_position_copy = rotor_position.copy() | ||
25 | rotor_position_copy = {value: key for key, value in rotor_position.items()} | 25 | rotor_position_copy = {value: key for key, value in rotor_position.items()} | ||
26 | #без да правя копие ми хвърля грешка, че не мога да access-на rotor_position | 26 | #без да правя копие ми хвърля грешка, че не мога да access-на rotor_position | ||
27 | decrypted_word = rotor(text, rotor_position_copy) | 27 | decrypted_word = rotor(text, rotor_position_copy) | ||
28 | decrypted_word = plugboard(decrypted_word, plugboard_position) | 28 | decrypted_word = plugboard(decrypted_word, plugboard_position) | ||
29 | return func(decrypted_word) | 29 | return func(decrypted_word) | ||
30 | return wrapper | 30 | return wrapper | ||
31 | return decorator | 31 | return decorator |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|