-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
39 lines (29 loc) · 1.15 KB
/
tests.py
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
import unittest
from fpecredit import *
class FpeTests(unittest.TestCase):
def test_output_length(self):
decrypt = False
cardnum = randint(1000000000000000, 9999999999999999)
key = 32*"A"
roundnum = randint(3, 9)
result = mainloop(cardnum, key, roundnum, decrypt)
self.assertEqual(len(result), 16)
def test_dec_output_length(self):
decrypt = True
cardnum = randint(1000000000000000, 9999999999999999)
key = 32*"A"
roundnum = randint(3, 9)
result = mainloop(cardnum, key, roundnum, decrypt)
self.assertEqual(len(result), 16)
def test_multiple_proper_decryptions(self):
for x in range(100):
decrypt = False
cardnum = randint(0000000000000000, 9999999999999999)
key = 32*"A"
roundnum = randint(3, 9)
encrypted = mainloop(cardnum, key, roundnum, decrypt)
decrypt = True
decrypted = mainloop(int(encrypted), key, roundnum, decrypt)
self.assertEqual(cardnum, int(decrypted))
if __name__ == '__main__':
unittest.main()