Crypto - Taaffeite Encryption
I heard that post-quantum cryptosystems are secure. So even your quantum computer can't break this one. -Nilabha Saha
Challenge
from sage.all import *
from secret import FLAG
degree = 256
vec_size = 3
p = 3329
smallness = 2
Q.<y> = PolynomialRing(GF(p))
R.<x> = Q.quotient(y**degree + 1)
def gen_small_vect():
return vector([R([randint(0, smallness) for _ in range(degree)]) for _ in range(vec_size)])
def gen_coeffs():
return Matrix([[R.random_element() for _ in range(vec_size)] for _ in range(vec_size)])
def encode_message(m):
bits = sum([[int(b) for b in bin(c)[2:].zfill(8)] for c in m], [])
return R(bits)
s = gen_small_vect()
coeffs = gen_coeffs()
assert len(FLAG)*8 <= degree
r = gen_small_vect()
err1 = gen_small_vect()
err2 = R([randint(0, smallness) for _ in range(degree)])
flag_b = encode_message(FLAG)
p_round = p//2 + 1
f = p_round*flag_b
ctxt = (coeffs.T*r + err1, (coeffs*s + gen_small_vect())*r + err2 + f)
noise = randint(-vec_size**degree, vec_size**degree)
noisy_s = noise*s
with open("data.txt", 'w') as f:
f.write(f"noisy_s: {noisy_s}\n")
f.write(f"ctxt: {ctxt}\n")Last updated