-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_cipher_test.py
More file actions
74 lines (55 loc) · 2.67 KB
/
simple_cipher_test.py
File metadata and controls
74 lines (55 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import unittest
from cipher import Caesar, Cipher
class CipherTest(unittest.TestCase):
def test_caesar_encode1(self):
self.assertEqual('lwlvdzhvrphsurjudpplqjlqsbwkrq',
Caesar().encode('itisawesomeprogramminginpython'))
def test_caesar_encode2(self):
self.assertEqual('yhqlylglylfl', Caesar().encode('venividivici'))
def test_caesar_encode3(self):
self.assertEqual('wzdvwkhqljkwehiruhfkulvwpdv',
Caesar().encode('\'Twas the night before Christmas'))
def test_caesar_encode_with_numbers(self):
self.assertEqual('jr', Caesar().encode('1, 2, 3, Go!'))
def test_caesar_decode(self):
self.assertEqual('venividivici', Caesar().decode('yhqlylglylfl'))
def test_cipher_encode1(self):
c = Cipher('a')
self.assertEqual('itisawesomeprogramminginpython',
c.encode('itisawesomeprogramminginpython'))
def test_cipher_encode2(self):
c = Cipher('aaaaaaaaaaaaaaaaaaaaaa')
self.assertEqual('itisawesomeprogramminginpython',
c.encode('itisawesomeprogramminginpython'))
def test_cipher_encode3(self):
c = Cipher('dddddddddddddddddddddd')
self.assertEqual('yhqlylglylfl', c.encode('venividivici'))
def test_cipher_encode4(self):
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
c = Cipher(key)
self.assertEqual('gccwkixcltycv', c.encode('diffiehellman'))
def test_cipher_encode_short_key(self):
c = Cipher('abcd')
self.assertEqual('abcdabcd', c.encode('aaaaaaaa'))
def test_cipher_compositiion1(self):
key = ('duxrceqyaimciuucnelkeoxjhdyduucpmrxmaivacmybmsdrzwqxvbxsy'
'gzsabdjmdjabeorttiwinfrpmpogvabiofqexnohrqu')
plaintext = 'adaywithoutlaughterisadaywasted'
c = Cipher(key)
self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
def test_cipher_compositiion2(self):
plaintext = 'adaywithoutlaughterisadaywasted'
c = Cipher()
self.assertEqual(plaintext, c.decode(c.encode(plaintext)))
def test_cipher_random_key(self):
c = Cipher()
self.assertTrue(len(c.key) >= 100,
'A random key must be generated when no key is given!')
self.assertTrue(c.key.islower() and c.key.isalpha(),
'All items in the key must be chars and lowercase!')
def test_cipher_wrong_key(self):
self.assertRaises(ValueError, Cipher, 'a1cde')
self.assertRaises(ValueError, Cipher, 'aBcde')
if __name__ == '__main__':
unittest.main()