This repository was archived by the owner on Jul 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 199
/
Copy pathfuzz_test.py
75 lines (61 loc) · 1.86 KB
/
fuzz_test.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
__author__ = 'L3odr0id'
"""
Fuzz testing
"""
import time
from fuzzingbook.Fuzzer import RandomFuzzer
from aes import AES
def test_system(key, data):
"""
Encrypt and decrypt @key and @data
"""
a = AES(key)
plaintext = data
encrypted = a.encrypt(plaintext)
decrypted = a.decrypt(encrypted)
# check if data is encrypted
assert encrypted != decrypted, 'Data is not encrypted!'
return decrypted
def fuzz_testing(num_of_tests=10):
"""
Do tests
"""
ok = True
start = time.clock()
errors = []
# generate integers. Max possible length is 38
r = RandomFuzzer(min_length=1, char_start=48, char_range=9, max_length=38)
dot = num_of_tests // 10 # decoration stuff
for i in range(0, num_of_tests):
if i % dot == 0:
print('.', end='')
# generate test case
key = int(r.fuzz())
data = int(r.fuzz())
# analyze output
try:
result = test_system(key, data)
if data != result:
errors.append('TEST ' + str(i) + ' FAILED\nKey = "' + str(key) + '"\nData = "' + str(data) + '"')
errors.append('Result = "'+str(result)+'"')
errors.append('Reason: Error in encryption - decryption process\n')
ok = False
except AssertionError:
errors.append('TEST '+str(i)+' FAILED\nKey = "'+str(key)+'"\nData = "'+str(data)+'"')
errors.append('Reason: Data was not encrypted\n')
ok = False
# print testing results
elapsed = time.clock()
elapsed = elapsed - start
print()
for i in errors:
print(i)
print('Ran ' + str(num_of_tests) + ' tests in '+str(round(elapsed, 3))+'s')
print()
if ok:
print('OK')
else:
print('FAILED')
if __name__ == "__main__":
print('Fuzz test started.')
fuzz_testing(1337)