-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (39 loc) · 1.17 KB
/
main.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
from random import randint
from rsa.rsa import RSA, Data
from blake.blake import Blake
from protocol import Client, Address
import time
def rsa_test():
start = time.perf_counter()
keys = RSA.generate_keys()
end = time.perf_counter()
print(f"Key generation time: \t{end - start}")
raw = 'Test test test'
print('Encrypting:', raw)
start = time.perf_counter()
encrypted = RSA.encrypt(raw, keys.public)
end = time.perf_counter()
print(f"Encryption time: \t{end - start}")
print('Encrypted:', encrypted.to_hex())
start = time.perf_counter()
decrypted = RSA.decrypt(encrypted, keys.private)
end = time.perf_counter()
print(f"Decryption time: \t{end - start}")
print(f"Decrypted: {decrypted.to_raw()}")
def blake_test():
blake = Blake()
data = b''
with open('/etc/passwd', 'rb') as f:
data = f.read()
digest = blake.hexdigest(data)
print(digest)
def protocol_test():
port = randint(5000, 5099)
print(f"port: {port}")
client = Client(port)
client.wait_handshake()
client.receive_message()
if __name__ == '__main__':
# rsa_test()
# blake_test()
protocol_test()