1def rotor(word, plugboard_position):
2
3 alphaBeta = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
4 for letter in word:
5 for curSet in plugboard_position:
6 if letter in curSet:
7 finedElemt = letter
8 curSet.remove(letter)
9 for l in alphaBeta:
10 if l in curSet:
11 letter = l
12 curSet.add(finedElemt)
13 print(letter, end="")
14
15
16
17
18
19
20def plugboard(word, rotor_position):
21 for e in word:
22 print(rotor_position[e], end="")
23 print("")
24
25
26
27
28#plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}]
29
30#rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p',
31# 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q',
32# 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o',
33# 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l',
34# 'm': 'r', 'c': 'k'}
35
36#word = 'enigma'
37
38#plugboard(word, rotor_position)
39#rotor(word, plugboard_position)
EEEEF
Stdout:
EEFE
======================================================================
ERROR: test_full_letter_set (test.TestCombination)
Test decrypting an encrypted text against itself.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 136, in test_full_letter_set
encryptor = enigma_encrypt(self.PLUGBOARD_POSITION, self.ROTOR_POSITION)
NameError: name 'enigma_encrypt' is not defined
======================================================================
ERROR: test_correct_decorator_order (test.TestDecorators)
Test whether the decorator is applying the functions in correct order.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 162, in test_correct_decorator_order
encryptor = enigma_encrypt(self.PLUGBOARD_POSITION, self.ROTOR_POSITION)
NameError: name 'enigma_encrypt' is not defined
======================================================================
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 110, in test_full_letter_set
decryptor = enigma_decrypt(self.PLUGBOARD_POSITION, self.ROTOR_POSITION)
NameError: name 'enigma_decrypt' is not defined
======================================================================
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 87, in test_full_letter_set
encryptor = enigma_encrypt(self.PLUGBOARD_POSITION, self.ROTOR_POSITION)
NameError: name 'enigma_encrypt' is not defined
======================================================================
ERROR: test_no_mapping (test.TestPlugboard)
Test the plugboard function with no mapping input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 40, in test_no_mapping
self.assertEqual(plugboard('enigma machine is working', []), 'enigma machine is working')
File "/tmp/solution.py", line 22, in plugboard
print(rotor_position[e], end="")
TypeError: list indices must be integers or slices, not str
======================================================================
ERROR: test_normal_case (test.TestPlugboard)
Test the plugboard function with normally expected input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 45, in test_normal_case
self.assertEqual(plugboard('this is a test input', plugboard_position), 'ihts ts z iysi tnpui')
File "/tmp/solution.py", line 22, in plugboard
print(rotor_position[e], end="")
TypeError: list indices must be integers or slices, not str
======================================================================
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 8, in rotor
curSet.remove(letter)
AttributeError: 'str' object has no attribute 'remove'
======================================================================
FAIL: test_empty (test.TestPlugboard)
Test the plugboard function with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 36, in test_empty
self.assertEqual(plugboard('', []), '')
AssertionError: None != ''
Stdout:
======================================================================
FAIL: test_empty (test.TestRotor)
Test the rotor function with empty input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 63, in test_empty
self.assertEqual(rotor('', self.ROTOR_POSITION), '')
AssertionError: None != ''
----------------------------------------------------------------------
Ran 9 tests in 0.001s
FAILED (failures=2, errors=7)
f | 1 | def rotor(word, plugboard_position): | f | 1 | def rotor(word, plugboard_position): |
2 | 2 | ||||
3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | 3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | ||
4 | for letter in word: | 4 | for letter in word: | ||
5 | for curSet in plugboard_position: | 5 | for curSet in plugboard_position: | ||
6 | if letter in curSet: | 6 | if letter in curSet: | ||
7 | finedElemt = letter | 7 | finedElemt = letter | ||
8 | curSet.remove(letter) | 8 | curSet.remove(letter) | ||
9 | for l in alphaBeta: | 9 | for l in alphaBeta: | ||
10 | if l in curSet: | 10 | if l in curSet: | ||
11 | letter = l | 11 | letter = l | ||
12 | curSet.add(finedElemt) | 12 | curSet.add(finedElemt) | ||
13 | print(letter, end="") | 13 | print(letter, end="") | ||
14 | 14 | ||||
15 | 15 | ||||
16 | 16 | ||||
17 | 17 | ||||
18 | 18 | ||||
19 | 19 | ||||
20 | def plugboard(word, rotor_position): | 20 | def plugboard(word, rotor_position): | ||
21 | for e in word: | 21 | for e in word: | ||
22 | print(rotor_position[e], end="") | 22 | print(rotor_position[e], end="") | ||
23 | print("") | 23 | print("") | ||
24 | 24 | ||||
25 | 25 | ||||
26 | 26 | ||||
27 | 27 | ||||
n | 28 | plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}] | n | 28 | #plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}] |
29 | 29 | ||||
n | 30 | rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', | n | 30 | #rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', |
31 | 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | 31 | # 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | ||
32 | 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | 32 | # 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | ||
33 | 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | 33 | # 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | ||
34 | 'm': 'r', 'c': 'k'} | 34 | # 'm': 'r', 'c': 'k'} | ||
35 | 35 | ||||
n | 36 | word = 'enigma' | n | 36 | #word = 'enigma' |
37 | 37 | ||||
t | 38 | plugboard(word, rotor_position) | t | 38 | #plugboard(word, rotor_position) |
39 | rotor(word, plugboard_position) | 39 | #rotor(word, plugboard_position) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def rotor(word, plugboard_position): | f | 1 | def rotor(word, plugboard_position): |
2 | 2 | ||||
n | 3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyz' | n | 3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' |
4 | for letter in word: | 4 | for letter in word: | ||
5 | for curSet in plugboard_position: | 5 | for curSet in plugboard_position: | ||
6 | if letter in curSet: | 6 | if letter in curSet: | ||
7 | finedElemt = letter | 7 | finedElemt = letter | ||
8 | curSet.remove(letter) | 8 | curSet.remove(letter) | ||
9 | for l in alphaBeta: | 9 | for l in alphaBeta: | ||
10 | if l in curSet: | 10 | if l in curSet: | ||
11 | letter = l | 11 | letter = l | ||
12 | curSet.add(finedElemt) | 12 | curSet.add(finedElemt) | ||
13 | print(letter, end="") | 13 | print(letter, end="") | ||
14 | 14 | ||||
15 | 15 | ||||
16 | 16 | ||||
17 | 17 | ||||
18 | 18 | ||||
19 | 19 | ||||
20 | def plugboard(word, rotor_position): | 20 | def plugboard(word, rotor_position): | ||
21 | for e in word: | 21 | for e in word: | ||
22 | print(rotor_position[e], end="") | 22 | print(rotor_position[e], end="") | ||
23 | print("") | 23 | print("") | ||
24 | 24 | ||||
25 | 25 | ||||
26 | 26 | ||||
27 | 27 | ||||
t | 28 | plugboard_position = [{'a', 'c'}, {'t', 'z'}] | t | 28 | plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}] |
29 | 29 | ||||
30 | rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', | 30 | rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', | ||
31 | 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | 31 | 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | ||
32 | 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | 32 | 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | ||
33 | 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | 33 | 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | ||
34 | 'm': 'r', 'c': 'k'} | 34 | 'm': 'r', 'c': 'k'} | ||
35 | 35 | ||||
36 | word = 'enigma' | 36 | word = 'enigma' | ||
37 | 37 | ||||
38 | plugboard(word, rotor_position) | 38 | plugboard(word, rotor_position) | ||
39 | rotor(word, plugboard_position) | 39 | rotor(word, plugboard_position) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
f | 1 | def rotor(word, plugboard_position): | f | 1 | def rotor(word, plugboard_position): |
2 | 2 | ||||
3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyz' | 3 | alphaBeta = 'abcdefghijklmnopqrstuvwxyz' | ||
4 | for letter in word: | 4 | for letter in word: | ||
5 | for curSet in plugboard_position: | 5 | for curSet in plugboard_position: | ||
6 | if letter in curSet: | 6 | if letter in curSet: | ||
7 | finedElemt = letter | 7 | finedElemt = letter | ||
8 | curSet.remove(letter) | 8 | curSet.remove(letter) | ||
9 | for l in alphaBeta: | 9 | for l in alphaBeta: | ||
10 | if l in curSet: | 10 | if l in curSet: | ||
11 | letter = l | 11 | letter = l | ||
12 | curSet.add(finedElemt) | 12 | curSet.add(finedElemt) | ||
13 | print(letter, end="") | 13 | print(letter, end="") | ||
14 | 14 | ||||
15 | 15 | ||||
16 | 16 | ||||
17 | 17 | ||||
18 | 18 | ||||
19 | 19 | ||||
20 | def plugboard(word, rotor_position): | 20 | def plugboard(word, rotor_position): | ||
21 | for e in word: | 21 | for e in word: | ||
22 | print(rotor_position[e], end="") | 22 | print(rotor_position[e], end="") | ||
23 | print("") | 23 | print("") | ||
24 | 24 | ||||
25 | 25 | ||||
26 | 26 | ||||
27 | 27 | ||||
n | 28 | #plugboard_position = [{'a', 'c'}, {'t', 'z'}] | n | 28 | plugboard_position = [{'a', 'c'}, {'t', 'z'}] |
29 | 29 | ||||
n | 30 | #rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', | n | 30 | rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p', |
31 | # 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | 31 | 's': 'e', 'x': 's', 'h': 'f', 'b': 'x', 'u': 'c', 'p': 'q', | ||
32 | # 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | 32 | 'r': 'g', 'q': 'j', 'e': 't', 'l': 'y', 'o': 'z', 'g': 'o', | ||
33 | # 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | 33 | 'k': 'b', 't': 'h', 'j': 'm', 'a': 'a', 'w': 'i', 'f': 'l', | ||
34 | # 'm': 'r', 'c': 'k'} | 34 | 'm': 'r', 'c': 'k'} | ||
35 | 35 | ||||
n | 36 | #word = 'enigma' | n | 36 | word = 'enigma' |
37 | 37 | ||||
t | 38 | #plugboard(word, rotor_position) | t | 38 | plugboard(word, rotor_position) |
39 | #rotor(word, plugboard_position) | 39 | rotor(word, plugboard_position) |
Legends | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
|
31.10.2023 18:08