Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import numpy as np
import sys
def gen_poly(n,q):
global xN_1
l = 0 #Gamma Distribution Location (Mean "center" of dist.)
poly = np.floor(np.random.normal(l,size=(n)))
while (len(poly) != n):
poly = np.floor(np.random.normal(l,size=(n)))
poly = np.floor(p.polydiv(poly,xN_1)[1]%q)
return poly
q=13
A = [4,1,11,10]
sA = [6,9,11,11]
eA =[0,-1,1,1]
n=4
print(A,sA,eA)
xN_1 = [1] + [0] * (n-1) + [1]
print(xN_1)
A = np.floor(np.polydiv(A,xN_1)[1])
bA = np.polymul(A,sA)%q
bA = np.floor(np.polydiv(bA,xN_1)[1])
bA = np.polyadd(bA,eA)%q
bA = np.floor(np.polydiv(bA,xN_1)[1])
print("Print output\n",bA)
xN_1 = [1] + [0] * (n-1) + [1]
A = np.floor(np.polydiv(A,xN_1)[1])
bA = np.polymul(A,sA)%q
bA = np.floor(np.polydiv(sA,xN_1)[1])
bA = np.polyadd(bA,eA)%q
sB = gen_poly(n,q)
eB = gen_poly(n,q)
bB = np.polymul(A,sB)%q
bB = np.floor(np.polydiv(sB,xN_1)[1])
bB = np.polyadd(bB,eB)%q
sharedAlice = np.floor(np.polymul(sA,bB)%q)
sharedAlice = np.floor(np.polydiv(sharedAlice,xN_1)[1])%q
sharedBob = np.floor(np.polymul(sB,bA)%q)
sharedBob = np.floor(np.polydiv(sharedBob,xN_1)[1])%q
# Public key and LWE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment