4 from cipher
.affine
import *
5 from support
.utilities
import *
7 class AffineTest(unittest
.TestCase
):
9 def test_encipher_letter(self
):
12 'hknqtwzcfiloruxadgjmpsvybeHKNQTWZCFILORUXADGJMPSVYBE'):
13 self
.assertEqual(affine_encipher_letter(p
, 3, 5, True), c
)
17 'filoruxadgjmpsvybehknqtwzcFILORUXADGJMPSVYBEHKNQTWZC'):
18 self
.assertEqual(affine_encipher_letter(p
, 3, 5, False), c
)
21 def test_decipher_letter(self
):
24 'hknqtwzcfiloruxadgjmpsvybeHKNQTWZCFILORUXADGJMPSVYBE'):
25 self
.assertEqual(affine_decipher_letter(c
, 3, 5, True), p
)
29 'filoruxadgjmpsvybehknqtwzcFILORUXADGJMPSVYBEHKNQTWZC'):
30 self
.assertEqual(affine_decipher_letter(c
, 3, 5, False), p
)
32 def test_encipher_message(self
):
33 self
.assertEqual(affine_encipher(
34 'hours passed during which jerico tried every trick he could think of',
36 'lmyfu bkuusd dyfaxw claol psfaom jfasd snsfg jfaoe ls omytd jlaxe mh')
39 def test_decipher_message(self
):
40 self
.assertEqual(affine_decipher('lmyfu bkuusd dyfaxw claol psfaom jfasd snsfg jfaoe ls omytd jlaxe mh',
42 'hours passed during which jerico tried every trick he could think of')
46 ciphertext
= '''lmyfu bkuusd dyfaxw claol psfaom jfasd snsfg jfaoe ls
47 omytd jlaxe mh jm bfmibj umis hfsul axubafkjamx. ls kffkxwsd jls
48 ofgbjmwfkiu olfmxmtmwaokttg jlsx ls kffkxwsd jlsi zg tsxwjl. jlsx
49 ls umfjsd jlsi zg hfsqysxog. ls dmmdtsd mx jls bats mh bkbsf. ls
50 bfmctsd kfmyxd jls lyj, mztanamyu xmc jm clm cku tmmeaxw kj lai
52 expected_key
= (15, 22, True)
53 expected_score
= -340.6011819
54 actual_key
, actual_score
= affine_break(ciphertext
)
55 self
.assertEqual(expected_key
, actual_key
)
56 self
.assertAlmostEqual(expected_score
, actual_score
)
58 if __name__
== '__main__':