1def plugboard(text, plug):
2 result = ''
3 for letter in text:
4 for i in plug:
5 if letter in i:
6 result += ''.join(i - set(letter))
7 break
8 else:
9 result += letter
10 print(result)
11 return result
12
13def rotor(text, rot):
14 result = ''
15 for letter in text:
16 result += str(rot.get(letter, ' '))
17 print(result)
18 return result
19
20def enigma_encrypt(plugboard_position, rotor_position):
21 def decorator(func):
22 def dummy_func(n):
23 n = plugboard(n, plugboard_position)
24 n = rotor(n,rotor_position)
25 return func(n)
26 return dummy_func
27 return decorator
28
29def enigma_decrypt(plugboard_position, rotor_position):
30 def decorator(func):
31 def dummy_func(n):
32 rotor_position_2 = {v:k for k,v in rotor_position.items()}
33 n = rotor(n,rotor_position_2)
34 n = plugboard(n, plugboard_position)
35 return func(n)
36 return dummy_func
37 return decorator
.........
----------------------------------------------------------------------
Ran 9 tests in 0.001s
OK
f | 1 | def plugboard(text, plug): | f | 1 | def plugboard(text, plug): |
2 | result = '' | 2 | result = '' | ||
n | 3 | for letter in text: | n | 3 | for letter in text: |
4 | flag = False | ||||
5 | for i in plug: | 4 | for i in plug: | ||
6 | if letter in i: | 5 | if letter in i: | ||
n | 7 | flag = True | n | ||
8 | result += ''.join(i - set(letter)) | 6 | result += ''.join(i - set(letter)) | ||
7 | break | ||||
9 | if not flag: | 8 | else: | ||
10 | result += letter | 9 | result += letter | ||
n | n | 10 | print(result) | ||
11 | return result | 11 | return result | ||
12 | 12 | ||||
13 | def rotor(text, rot): | 13 | def rotor(text, rot): | ||
14 | result = '' | 14 | result = '' | ||
15 | for letter in text: | 15 | for letter in text: | ||
n | 16 | if letter not in rot: | n | 16 | result += str(rot.get(letter, ' ')) |
17 | result += letter | 17 | print(result) | ||
18 | else: | ||||
19 | result += rot[letter] | ||||
20 | return result | 18 | return result | ||
21 | 19 | ||||
22 | def enigma_encrypt(plugboard_position, rotor_position): | 20 | def enigma_encrypt(plugboard_position, rotor_position): | ||
n | 23 | def decorator1(func): | n | 21 | def decorator(func): |
24 | def dummy_func(n): | 22 | def dummy_func(n): | ||
25 | n = plugboard(n, plugboard_position) | 23 | n = plugboard(n, plugboard_position) | ||
26 | n = rotor(n,rotor_position) | 24 | n = rotor(n,rotor_position) | ||
27 | return func(n) | 25 | return func(n) | ||
28 | return dummy_func | 26 | return dummy_func | ||
n | 29 | return decorator1 | n | 27 | return decorator |
30 | 28 | ||||
31 | def enigma_decrypt(plugboard_position, rotor_position): | 29 | def enigma_decrypt(plugboard_position, rotor_position): | ||
n | 32 | def decorator2(func): | n | 30 | def decorator(func): |
33 | def dummy_func(n): | 31 | def dummy_func(n): | ||
n | 34 | rotor_position_2={v:k for k,v in rotor_position.items()} | n | 32 | rotor_position_2 = {v:k for k,v in rotor_position.items()} |
35 | n = rotor(n,rotor_position_2) | 33 | n = rotor(n,rotor_position_2) | ||
36 | n = plugboard(n, plugboard_position) | 34 | n = plugboard(n, plugboard_position) | ||
37 | return func(n) | 35 | return func(n) | ||
38 | return dummy_func | 36 | return dummy_func | ||
t | 39 | return decorator2 | t | 37 | return decorator |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def plugboard(text, plug): | f | 1 | def plugboard(text, plug): |
2 | result = '' | 2 | result = '' | ||
3 | for letter in text: | 3 | for letter in text: | ||
4 | flag = False | 4 | flag = False | ||
5 | for i in plug: | 5 | for i in plug: | ||
6 | if letter in i: | 6 | if letter in i: | ||
7 | flag = True | 7 | flag = True | ||
8 | result += ''.join(i - set(letter)) | 8 | result += ''.join(i - set(letter)) | ||
9 | if not flag: | 9 | if not flag: | ||
10 | result += letter | 10 | result += letter | ||
11 | return result | 11 | return result | ||
12 | 12 | ||||
13 | def rotor(text, rot): | 13 | def rotor(text, rot): | ||
14 | result = '' | 14 | result = '' | ||
15 | for letter in text: | 15 | for letter in text: | ||
16 | if letter not in rot: | 16 | if letter not in rot: | ||
17 | result += letter | 17 | result += letter | ||
18 | else: | 18 | else: | ||
19 | result += rot[letter] | 19 | result += rot[letter] | ||
20 | return result | 20 | return result | ||
21 | 21 | ||||
22 | def enigma_encrypt(plugboard_position, rotor_position): | 22 | def enigma_encrypt(plugboard_position, rotor_position): | ||
23 | def decorator1(func): | 23 | def decorator1(func): | ||
24 | def dummy_func(n): | 24 | def dummy_func(n): | ||
n | 25 | n=plugboard(n, plugboard_position) | n | 25 | n = plugboard(n, plugboard_position) |
26 | n=rotor(n,rotor_position) | 26 | n = rotor(n,rotor_position) | ||
27 | return func(n) | 27 | return func(n) | ||
28 | return dummy_func | 28 | return dummy_func | ||
29 | return decorator1 | 29 | return decorator1 | ||
30 | 30 | ||||
31 | def enigma_decrypt(plugboard_position, rotor_position): | 31 | def enigma_decrypt(plugboard_position, rotor_position): | ||
32 | def decorator2(func): | 32 | def decorator2(func): | ||
33 | def dummy_func(n): | 33 | def dummy_func(n): | ||
34 | rotor_position_2={v:k for k,v in rotor_position.items()} | 34 | rotor_position_2={v:k for k,v in rotor_position.items()} | ||
t | 35 | n=rotor(n,rotor_position_2) | t | 35 | n = rotor(n,rotor_position_2) |
36 | n=plugboard(n, plugboard_position) | 36 | n = plugboard(n, plugboard_position) | ||
37 | return func(n) | 37 | return func(n) | ||
38 | return dummy_func | 38 | return dummy_func | ||
39 | return decorator2 | 39 | return decorator2 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def plugboard(text, plug): | f | 1 | def plugboard(text, plug): |
2 | result = '' | 2 | result = '' | ||
3 | for letter in text: | 3 | for letter in text: | ||
4 | flag = False | 4 | flag = False | ||
5 | for i in plug: | 5 | for i in plug: | ||
6 | if letter in i: | 6 | if letter in i: | ||
n | 7 | flag=True | n | 7 | flag = True |
8 | result += ''.join(i - set(letter)) | 8 | result += ''.join(i - set(letter)) | ||
9 | if not flag: | 9 | if not flag: | ||
10 | result += letter | 10 | result += letter | ||
11 | return result | 11 | return result | ||
12 | 12 | ||||
13 | def rotor(text, rot): | 13 | def rotor(text, rot): | ||
14 | result = '' | 14 | result = '' | ||
15 | for letter in text: | 15 | for letter in text: | ||
16 | if letter not in rot: | 16 | if letter not in rot: | ||
17 | result += letter | 17 | result += letter | ||
18 | else: | 18 | else: | ||
19 | result += rot[letter] | 19 | result += rot[letter] | ||
20 | return result | 20 | return result | ||
21 | 21 | ||||
22 | def enigma_encrypt(plugboard_position, rotor_position): | 22 | def enigma_encrypt(plugboard_position, rotor_position): | ||
23 | def decorator1(func): | 23 | def decorator1(func): | ||
n | 24 | def ankara(n): | n | 24 | def dummy_func(n): |
25 | n=plugboard(n, plugboard_position) | 25 | n=plugboard(n, plugboard_position) | ||
26 | n=rotor(n,rotor_position) | 26 | n=rotor(n,rotor_position) | ||
27 | return func(n) | 27 | return func(n) | ||
n | 28 | return ankara | n | 28 | return dummy_func |
29 | return decorator1 | 29 | return decorator1 | ||
30 | 30 | ||||
31 | def enigma_decrypt(plugboard_position, rotor_position): | 31 | def enigma_decrypt(plugboard_position, rotor_position): | ||
32 | def decorator2(func): | 32 | def decorator2(func): | ||
n | 33 | def ankara(n): | n | 33 | def dummy_func(n): |
34 | rotor_position_2={v:k for k,v in rotor_position.items()} | 34 | rotor_position_2={v:k for k,v in rotor_position.items()} | ||
35 | n=rotor(n,rotor_position_2) | 35 | n=rotor(n,rotor_position_2) | ||
36 | n=plugboard(n, plugboard_position) | 36 | n=plugboard(n, plugboard_position) | ||
37 | return func(n) | 37 | return func(n) | ||
t | 38 | return ankara | t | 38 | return dummy_func |
39 | return decorator2 | 39 | return decorator2 |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|