Skip to content

Instantly share code, notes, and snippets.

@bquast
Last active July 29, 2019 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bquast/4b9ffca72526c4a0b758e24715e88a52 to your computer and use it in GitHub Desktop.
Save bquast/4b9ffca72526c4a0b758e24715e88a52 to your computer and use it in GitHub Desktop.
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