-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunit_tests
More file actions
executable file
·83 lines (67 loc) · 3.13 KB
/
unit_tests
File metadata and controls
executable file
·83 lines (67 loc) · 3.13 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
75
76
77
78
79
80
81
82
83
#!/usr/bin/env python3
import sys
from Xor.Xor import Xor
from Aes.AES import Aes
from RSA.RSA import Rsa
def xorTests():
#-b test
xor = Xor("576861742069732064656164206d6179206e6576657220646965")
cypher = xor._encrypt("You know nothing, Jon Snow")
assert cypher == "20070f2700071c6a4449060a490515164e4e12190b190011063c"
decypher = xor._decrypt(cypher)
assert decypher == "You know nothing, Jon Snow"
# Long key test
xor = Xor("576861742069732064656164206d6179206e65766572206469651234")
cypher = xor._encrypt("You know nothing, Jon Snow")
decypher = xor._decrypt(cypher)
assert decypher == "You know nothing, Jon Snow"
# Short key test
xor = Xor("576861742069732064656164206d6179206e6576657220646965")
cypher = xor._encrypt("You know nothing, Jon Snow is the best")
decypher = xor._decrypt(cypher)
assert decypher == "You know nothing, Jon Snow is the best"
def aesTests():
#-b test
aes = Aes("57696e74657220697320636f6d696e67")
cypher = aes._encrypt("All men must die")
assert cypher == "744ce22c385958348f0df26eceb62eef"
decypher = aes._decrypt("744ce22c385958348f0df26eceb62eef")
assert decypher == "All men must die"
# Short messag test
aes = Aes("57696e74657220697320636f6d696e67")
cypher = aes._encrypt("All men must d")
assert cypher == "6449baa56dbe4ee34ea89a6d2dcb92b9"
decypher = aes._decrypt("6449baa56dbe4ee34ea89a6d2dcb92b9")
assert decypher == "All men must d"
# Long messag test
aes = Aes("57696e74657220697320636f6d696e67")
cypher = aes._encrypt("All men must die ahah")
assert cypher == "744ce22c385958348f0df26eceb62eefdd1ff81962eabbbdae56423d2d9df7dd"
decypher = aes._decrypt("744ce22c385958348f0df26eceb62eefdd1ff81962eabbbdae56423d2d9df7dd")
assert decypher == "All men must die ahah"
def rsaGenTests():
rsa = Rsa("")
p = "4b1da73924978f2e9c1f04170e46820d648edbee12ccf4d4462af89b080c86e1"
q = "bb3ca1e126f7c8751bd81bc8daa226494efb3d128f72ed9f6cacbe96e14166cb"
pValue = int(''.join([p[i:i + 2] for i in range(0, len(p), 2)][::-1]), 16)
qValue = int(''.join([q[i:i + 2] for i in range(0, len(q), 2)][::-1]), 16)
rsa.setGenValue(pValue, qValue)
rsa.generateKeys()
assert rsa.getPublicKey() == "010001-c9f91a9ff3bd6d84005b9cc8448296330bd23480f8cf8b36fd4edd0a8cd925de139a0076b962f4d57f50d6f9e64e7c41587784488f923dd60136c763fd602fb3"
assert rsa.getPrivateKey() == "81b08f4eb6dd8a4dd21728e5194dfc4e349829c9991c8b5e44b31e6ceee1e56a11d66ef23389be92ef7a4178470693f509c90b86d4a1e1831056ca0757f3e209-c9f91a9ff3bd6d84005b9cc8448296330bd23480f8cf8b36fd4edd0a8cd925de139a0076b962f4d57f50d6f9e64e7c41587784488f923dd60136c763fd602fb3"
rsa = Rsa("")
p = "d3"
q = "e3"
pValue = int(''.join([p[i:i + 2] for i in range(0, len(p), 2)][::-1]), 16)
qValue = int(''.join([q[i:i + 2] for i in range(0, len(q), 2)][::-1]), 16)
rsa.setGenValue(pValue, qValue)
rsa.generateKeys()
assert rsa.getPublicKey() == "0101-19bb"
assert rsa.getPrivateKey() == "9d5b-19bb"
def main():
xorTests()
aesTests()
rsaGenTests()
if __name__ == "__main__":
main()
print("Everything's good")