Skip to content

Instantly share code, notes, and snippets.

@amir734jj
Created September 30, 2016 04:52
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 amir734jj/86efb6bf8897902317c7e1d8e73f8618 to your computer and use it in GitHub Desktop.
Save amir734jj/86efb6bf8897902317c7e1d8e73f8618 to your computer and use it in GitHub Desktop.
Ring LWE KE
from random import randint
def generate_matrix(dimention, modulus):
array = []
upper_limit = modulus * dimention
for i in range(0, dimention):
f = 0
for j in range(0, dimention):
f = f + (randrange(modulus, upper_limit) * x^j)
array.append(f)
return Matrix(array)
dimention = 8
modulus = 65537
R = PolynomialRing(GF(65537), "X")
X = R.gen()
S = R.quotient(X^1024 + 1, "x")
x = S.gen()
A = generate_matrix(dimention, modulus)
S = generate_matrix(dimention, modulus)
S_ = generate_matrix(dimention, modulus)
B = A.transpose()*S
B_ = A.transpose()*S_
alice = S*B_
bob = S_*B
print alice == bob
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment