Created
October 1, 2016 13:22
-
-
Save avanpo/1a3b58ed8b63be6d54b28b2df9a43f48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Simple test to verify Ring-LWE exchange, without actually | |
# adding any error. | |
from random import randint | |
def generate_matrix(dimension, modulus): | |
array = [] | |
upper_limit = modulus * dimension | |
for i in range(0, dimension): | |
f = 0 | |
for j in range(0, dimension): | |
f = f + (randrange(0, upper_limit) * x^j) | |
array.append(f) | |
return Matrix(array) | |
dimension = 8 | |
modulus = 65537 | |
R = PolynomialRing(GF(65537), "X") | |
X = R.gen() | |
S = R.quotient(X^1024 + 1, "x") | |
x = S.gen() | |
A = generate_matrix(dimension, modulus) | |
#print "A: " + str(A.nrows()) + " x " + str(A.ncols()) | |
#print A.str() | |
S = generate_matrix(dimension, modulus) | |
#print "S: " + str(S.nrows()) + " x " + str(S.ncols()) | |
#print S.str() | |
S_ = generate_matrix(dimension, modulus) | |
#print "S': " + str(S_.nrows()) + " x " + str(S_.ncols()) | |
#print S_.str() | |
B = A.transpose()*S | |
#print "B: " + str(B.nrows()) + " x " + str(B.ncols()) | |
#print B.str() | |
B_ = S_.transpose()*A | |
#print "B': " + str(B_.nrows()) + " x " + str(B_.ncols()) | |
#print B_.str() | |
alice = B_.transpose()*S.transpose() | |
#print "alice: " + str(alice.nrows()) + " x " + str(alice.ncols()) | |
#print alice.str() | |
bob = (S_*B.transpose()).transpose() | |
#print "bob: " + str(bob.nrows()) + " x " + str(bob.ncols()) | |
#print bob.str() | |
print alice == bob |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment