-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_enDom.py
47 lines (39 loc) · 943 Bytes
/
example_enDom.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
# Description of this example is provided in NTRU.md
from ntru import *
#Bob
Bob=Ntru(7,29,491531)
f=[1,1,-1,0,-1,1]
g=[-1,0,1,1,0,0,-1]
d=2
Bob.genPublicKey(f,g,2)
pub_key=Bob.getPublicKey()
print "Public Key :",pub_key
#Alice
M=list()
M.append([1,1])
M.append([1,1,1])
M.append([1,0,1])
M.append([0,1,1])
M.append([0,1,0,1])
M.append([1])
R=list()
R.append([-1,-1,1,1])
R.append([1,1,-1,0,-1])
R.append([1,-1,0,1,0,0,-1])
R.append([-1,0,0,-1,0,1,1])
R.append([0,-1,0,0,-1,1,1])
R.append([1,0,0,-1,-1,1])
Alice=Ntru(7,29,491531)
Alice.setPublicKey(pub_key)
E=[0]*len(M)
for i in range(0,len(M)):
E[i]=Alice.encrypt(M[i],R[i])
m1=poly.multPoly(E[0],E[1])
m2=poly.multPoly(E[2],E[3])
m3=poly.multPoly(E[4],E[5])
m1=poly.addPoly(m1,m2)
m1=poly.addPoly(m1,m3)
print "Encrypted Computation: ",m1
#Bob
print "Decrypted Computation: ", Bob.decryptSQ(m1)
print "Results match with those in the paper"