Skip to content

Instantly share code, notes, and snippets.

View amir734jj's full-sized avatar
🎮
Working from home

Seyedamirhossein Hesamian amir734jj

🎮
Working from home
  • Microsoft, Redmond
  • United States
  • LinkedIn in/hesamian
View GitHub Profile
@amir734jj
amir734jj / flatten_unflatten_matrix .sage
Created October 21, 2016 03:28
flatten and unflatten matrix in Sage via numpy
import numpy as np
from sage.stats.distributions.discrete_gaussian_lattice import DiscreteGaussianDistributionLatticeSampler
n = 256
D = DiscreteGaussianDistributionLatticeSampler(ZZ^n, 3.0)
arr = [list(D()) for i in range(n)]
flat = flatten(list(arr))
@amir734jj
amir734jj / Ring-LWE.sage
Created September 30, 2016 04:52
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)
Ring ring1 = new Ring("x^2 + 23 *3y + x^3y^z");
Ring ring2 = new Ring("x^2 + 23 *3y + x*3y+z");
Ring ring3 = new Ring("x^2 + (23 *3y) + x^3y^z");
Ring ring4 = new Ring("x^2 + (23 *(2 + x)*3y)+z");
Ring ring5 = new Ring("2+16/2^4");
Ring ring6 = new Ring("2+16/2^4*2");
Ring ring7 = new Ring("2+16/2^4*2+(3-1*3-4^4^5)");
Ring ring8 = new Ring("4^4^5");
Ring ring9 = new Ring("4^4^5*3/3-1^4^5");
Ring ring10 = new Ring("4^4^5*3/3-1^(4^5)");
Double N = new Double(
"16260595201356777876687102055392856230368799478725437225418970788404092751540966827614883675066492383688147288741223234174448378892794567789551235835087027626536919406320142455677084743499141155821894102610573207343199194327005172833989486958434982393556326206485954223151805798621294965926069728816780985683043030371485847746616146554612001066554175545753760388987584593091716701780398711910886679925612838955858736102229719042291682456480437908426849734556856917891628730543729446245974891735371991588505429152639045721840213451875487038496578525189542369448895368117152818687795094021869963915318643663536132393791");
double delta = 0.26;
System.out.print(Math.pow(N.doubleValue(), delta));