-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanalysis.py
72 lines (65 loc) · 2.19 KB
/
analysis.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
import datetime
from random import randint
import fm
from paillier import PublicKey, PrivateKey, encrypt, decrypt
import env
import server
def analyze_insert_query():
i = 1
start_time = datetime.datetime.now()
delta = datetime.datetime.now() - start_time
while delta.total_seconds() < 1:
id = i
name = fm.convertTextToBigInt('My Name')
salary = 12000
bonus = 2000
record = {
'id': id,
'name': encrypt(name, pub_key),
'salary': encrypt(salary, pub_key),
'bonus': encrypt(bonus, pub_key)
}
server.insert('employees', record)
i = i + 1
delta = datetime.datetime.now() - start_time
print(i)
def analyze_select_query():
i = 1
start_time = datetime.datetime.now()
delta = datetime.datetime.now() - start_time
while delta.total_seconds() < 1:
id = randint(1, 50)
record = server.select('employees', id)
name = fm.convertBigIntToText(decrypt(int(record[1]), pub_key, priv_key))
salary = decrypt(int(record[2]), pub_key, priv_key)
bonus = decrypt(int(record[3]), pub_key, priv_key)
i = i + 1
delta = datetime.datetime.now() - start_time
print(i)
def analyze_select_query_with_addition():
i = 1
start_time = datetime.datetime.now()
delta = datetime.datetime.now() - start_time
while delta.total_seconds() < 1:
id = randint(1, 50)
earning_cp = server.compute_add('employees', id, 'salary', 'bonus')
earning = decrypt(earning_cp, pub_key, priv_key)
i = i + 1
delta = datetime.datetime.now() - start_time
print(i)
def analyze_update_query_with_multiplication():
i = 1
start_time = datetime.datetime.now()
delta = datetime.datetime.now() - start_time
while delta.total_seconds() < 1:
id = randint(1, 50)
server.update_mul('employees', id, 'bonus', 2)
i = i + 1
delta = datetime.datetime.now() - start_time
print(i)
pub_key = PublicKey(env.n, env.g)
priv_key = PrivateKey(env.p, env.q)
# analyze_insert_query()
# analyze_select_query()
# analyze_select_query_with_addition()
# analyze_update_query_with_multiplication()