4 from szyfrow
.vigenere
import *
5 from szyfrow
.support
.utilities
import *
8 def test_vigenere_encipher_message():
9 enciphered
= vigenere_encipher('hello', 'abc')
11 assert enciphered
== expected
14 def test_vigenere_decipher_message():
15 deciphered
= vigenere_decipher('hfnlp', 'abc')
17 assert deciphered
== expected
19 def test_beaufort_encipher_message():
20 enciphered
= beaufort_encipher('inhisjournaldatedtheidesofoctober', 'arcanaimperii')
21 expected
= 'sevsvrusyrrxfayyxuteemazudmpjmmwr'
22 assert enciphered
== expected
24 def test_beaufort_decipher_message():
25 deciphered
= beaufort_encipher('sevsvrusyrrxfayyxuteemazudmpjmmwr', 'arcanaimperii')
26 expected
= 'inhisjournaldatedtheidesofoctober'
27 assert deciphered
== expected
30 def test_vigenere_keyword_break():
31 ciphertext
= vigenere_encipher(sanitise('this is a test message for the vigenere decipherment'), 'cat')
33 expected_score
= -52.9472712
35 actual_key
, actual_score
= vigenere_keyword_break(ciphertext
, wordlist
=['cat', 'elephant', 'kangaroo'])
36 assert expected_key
== actual_key
37 assert expected_score
== pytest
.approx(actual_score
)
39 def test_vigenere_frequency_break():
40 ciphertext
= vigenere_encipher(sanitise("It is time to " \
41 "run. She is ready and so am I. I stole Daniel's pocketbook this " \
42 "afternoon when he left his jacket hanging on the easel in the " \
43 "attic. I jump every time I hear a footstep on the stairs, " \
44 "certain that the theft has been discovered and that I will " \
45 "be caught. The SS officer visits less often now that he is " \
47 expected_key
= 'florence'
48 expected_score
= -307.5473096
49 actual_key
, actual_score
= vigenere_frequency_break(ciphertext
)
50 assert expected_key
== actual_key
51 assert expected_score
== pytest
.approx(actual_score
)
54 def test_beaufort_sub_break():
56 ciphertext
= 'samwpplggnnmmyaazgympjapopnwiywwomwspgpjmefwmawx' \
57 'jafjhxwwwdigxshnlywiamhyshtasxptwueahhytjwsn'
59 expected_score
= -117.4492
60 actual_key
, actual_score
= beaufort_sub_break(ciphertext
)
61 assert expected_key
== actual_key
62 assert expected_score
== pytest
.approx(actual_score
)
64 ciphertext
= 'eyprzjjzznxymrygryjqmqhznjrjjapenejznawngnnezgza' \
65 'dgndknaogpdjneadadazlhkhxkryevrronrmdjnndjlo'
67 expected_score
= -114.9598
68 actual_key
, actual_score
= beaufort_sub_break(ciphertext
)
69 assert expected_key
== actual_key
70 assert expected_score
== pytest
.approx(actual_score
)
73 def test_beaufort_frequency_break():
74 ciphertext
= beaufort_encipher(sanitise("It is time to " \
75 "run. She is ready and so am I. I stole Daniel's pocketbook this " \
76 "afternoon when he left his jacket hanging on the easel in the " \
77 "attic. I jump every time I hear a footstep on the stairs, " \
78 "certain that the theft has been discovered and that I will " \
79 "be caught. The SS officer visits less often now that he is " \
81 expected_key
= 'florence'
82 expected_score
= -307.5473096
83 actual_key
, actual_score
= beaufort_frequency_break(ciphertext
)
84 assert expected_key
== actual_key
85 assert expected_score
== pytest
.approx(actual_score
)
88 def test_beaufort_variant_frequency_break():
89 ciphertext
= beaufort_variant_encipher(sanitise("It is time to " \
90 "run. She is ready and so am I. I stole Daniel's pocketbook this " \
91 "afternoon when he left his jacket hanging on the easel in the " \
92 "attic. I jump every time I hear a footstep on the stairs, " \
93 "certain that the theft has been discovered and that I will " \
94 "be caught. The SS officer visits less often now that he is " \
96 expected_key
= 'florence'
97 expected_score
= -307.5473096
98 actual_key
, actual_score
= beaufort_variant_frequency_break(ciphertext
)
99 assert expected_key
== actual_key
100 assert expected_score
== pytest
.approx(actual_score
)