gwrizienn/test.sage
2025-07-21 19:34:51 +02:00

39 lines
758 B
Python

q = 50177
Fq.<yq> = PolynomialRing(ZZ.quotient(q))
Rq = Fq.quotient(yq**256+1, "xq")
xq = Rq.gen()
F2q.<y2q> = PolynomialRing(ZZ.quotient(q*2))
R2q = F2q.quotient(y2q**256+1, "x2q")
x2q = R2q.gen()
F2.<y2> = PolynomialRing(ZZ.quotient(2))
R2 = F2.quotient(y2**256+1, "x2")
x2 = R2.gen()
def center(x, m):
x = x % m
if x < m/2:
return x
else:
return x - m
def f(x):
return (R2([int(i)%2 for i in x.list()]), Rq([int(i)%q for i in x.list()]))
def g(a, b):
al = a.list()
bl = b.list()
return R2q([int(al[i])*q-int(bl[i])*2*(q//2) for i in range(len(al))])
def add(ab, cd):
return (ab[0]+cd[0], ab[1]+cd[1])
def mul(ab, cd):
return (ab[0]*cd[0], ab[1]*cd[1])
a = -x2q**2 + 3*x2q + 2
b = 4*x2q + x2q**4
print(g(*mul(f(a), f(b))))
print(a*b)