-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed.py
48 lines (39 loc) · 1.11 KB
/
speed.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
'''
CSCI 334: Distributed Systems
Williams College
Spring 2014
Final Project: BLiP: Peer-to-Peer Chat
Authors:
Jeremy Boissevain
Nile Livingston
Nehemiah Paramore
This program was used to investigate the average time needed for RSA key
generation, encryption, and decryption using 512-bit keys.
'''
import rsa
import time
gen_times = []
encr_times = []
decr_times = []
# Each iteration is a trial.
for i in range (1, 101):
print str(i) + "..."
# Record key generation time.
start_time = time.time()
(pub, priv) = rsa.newkeys(512)
gen_times.append(time.time() - start_time)
# Record encryption time.
start_time = time.time()
encrypted = rsa.encrypt("xxxxxxxxxx", pub)
encr_times.append(time.time() - start_time)
# Record decryption time.
start_time = time.time()
rsa.decrypt(encrypted, priv)
decr_times.append(time.time() - start_time)
# Print averages.
print "Generation:"
print reduce(lambda x, y: x + y, gen_times) / len(gen_times)
print "Encryption:"
print reduce(lambda x, y: x + y, encr_times) / len(encr_times)
print "Decryption:"
print reduce(lambda x, y: x + y, decr_times) / len(decr_times)