forked from Varbin/xtea
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testXtea.py
78 lines (58 loc) · 1.77 KB
/
testXtea.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
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
75
76
77
78
import unittest
import os
from time import clock
from xtea import MODE_CBC, MODE_CTR, MODE_ECB, MODE_OFB, XTEACipher
from counter import Counter
def _test_mode(mode):
plain = os.urandom(56)*8
counter = Counter(os.urandom(8))
key = os.urandom(16)
iv = os.urandom(8)
e = XTEACipher(key, IV=iv, counter=counter, mode=mode)
encrypted = e.encrypt(plain)
d = XTEACipher(key, IV=iv, counter=counter, mode=mode)
counter.reset()
decrypted = d.decrypt(encrypted)
if plain != decrypted:
raise Exception("Invalid decryption!")
class TestModes(unittest.TestCase):
def testECB(self):
print("Testing ECB")
start = clock()
for i in range(250):
_test_mode(MODE_ECB)
end = clock()
time = end - start
print("Time: %s" % str(time))
def testCBC(self):
print("Testing CBC")
start = clock()
for i in range(250):
_test_mode(MODE_CBC)
end = clock()
time = end - start
print("Time: %s" % str(time))
def testCFB(self):
print("Testing CFB")
start = clock()
for i in range(250):
_test_mode(MODE_CBC)
end = clock()
time = end - start
print("Time: %s" % str(time))
def testOFB(self):
print("Testing OFB")
start = clock()
for i in range(250):
_test_mode(MODE_OFB)
end = clock()
time = end - start
print("Time: %s" % str(time))
def testCTR(self):
print("Testing CTR")
start = clock()
for i in range(250):
_test_mode(MODE_CTR)
end = clock()
time = end - start
print("Time: %s" % str(time))