Mateusz carried a huge jar of small papers with public keys written on them, but he tripped and accidentally dropped them into the scanner and made a txt file out of them! D: Note: This challenge is just an introduction to RLWE, the flag is (in standard format) encoded inside the private key.
baby_rlwe.sage
from sage.stats.distributions.discrete_gaussian_polynomial import DiscreteGaussianDistributionPolynomialSampler as d_gaussflag =bytearray(raw_input())
flag =list(flag)n =len(flag)
q =40961## Finite Field of size q.
F = GF(q)## Univariate Polynomial Ring in y over Finite Field of size q
R.<y>= PolynomialRing(F)## Univariate Quotient Polynomial Ring in x over Finite Field of size 40961 with modulus b^n + 1
S.<x>= R.quotient(y^n +1)defgen_small_poly():sigma =2/sqrt(2*pi)d = d_gauss(S, n, sigma)return d()defgen_large_poly():return S.random_element()## Public key 1
a = gen_large_poly()## Secret key
s = S(flag)file_out =open("downloads/public_keys.txt","w")
file_out.write("a: "+str(a)+"\n")for i inrange(100):## Errore = gen_small_poly()## Public key 2b = a*s + efile_out.write("b: "+str(b)+"\n")file_out.close()