Домашни > Енигма > Решения > Решението на Михаил Йорданов

Резултати
0 точки от тестове
0 точки от учител

0 точки общо

0 успешни теста
9 неуспешни теста
Код
Скрий всички коментари

 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)

Дискусия
История

f1def rotor(word, plugboard_position):f1def rotor(word, plugboard_position):
22
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 = letter7                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 = l11                        letter = l
12                curSet.add(finedElemt)12                curSet.add(finedElemt)
13        print(letter,  end="")13        print(letter,  end="")
14        14        
1515
16    16    
1717
1818
1919
20def plugboard(word, rotor_position):20def 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("")
2424
2525
26    26    
2727
n28plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}]n28#plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}]
2929
n30rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p',n30#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'}
3535
n36word = 'enigma'n36#word = 'enigma'
3737
t38plugboard(word, rotor_position)t38#plugboard(word, rotor_position)
39rotor(word, plugboard_position)39#rotor(word, plugboard_position)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def rotor(word, plugboard_position):f1def rotor(word, plugboard_position):
22
n3    alphaBeta = 'abcdefghijklmnopqrstuvwxyz'n3    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 = letter7                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 = l11                        letter = l
12                curSet.add(finedElemt)12                curSet.add(finedElemt)
13        print(letter,  end="")13        print(letter,  end="")
14        14        
1515
16    16    
1717
1818
1919
20def plugboard(word, rotor_position):20def 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("")
2424
2525
26    26    
2727
t28plugboard_position = [{'a', 'c'}, {'t', 'z'}]t28plugboard_position = [{'a', 'c'}, {'t', 'z'},{'e', 'n'}]
2929
30rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p',30rotor_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'}
3535
36word = 'enigma'36word = 'enigma'
3737
38plugboard(word, rotor_position)38plugboard(word, rotor_position)
39rotor(word, plugboard_position)39rotor(word, plugboard_position)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op

f1def rotor(word, plugboard_position):f1def rotor(word, plugboard_position):
22
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 = letter7                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 = l11                        letter = l
12                curSet.add(finedElemt)12                curSet.add(finedElemt)
13        print(letter,  end="")13        print(letter,  end="")
14        14        
1515
16    16    
1717
1818
1919
20def plugboard(word, rotor_position):20def 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("")
2424
2525
26    26    
2727
n28#plugboard_position = [{'a', 'c'}, {'t', 'z'}]n28plugboard_position = [{'a', 'c'}, {'t', 'z'}]
2929
n30#rotor_position = {'v': 'd', 'd': 'v', 'y': 'u', 'n': 'n', 'i': 'w', 'z': 'p',n30rotor_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'}
3535
n36#word = 'enigma'n36word = 'enigma'
3737
t38#plugboard(word, rotor_position)t38plugboard(word, rotor_position)
39#rotor(word, plugboard_position)39rotor(word, plugboard_position)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op