crypto: interpolation

This commit is contained in:
agatha 2024-10-25 16:23:41 -04:00
parent 6013199f17
commit 9e8502081c
4 changed files with 48 additions and 0 deletions

Binary file not shown.

View File

@ -0,0 +1,11 @@
FROM sagemath/sagemath:latest
RUN sudo apt update -y && sudo apt install -y socat
COPY --chown=sage . .
RUN chmod 755 entry.sh chall.sage
EXPOSE ${LISTEN_PORT}
ENTRYPOINT ["/home/sage/entry.sh"]

View File

@ -0,0 +1,31 @@
#!/usr/bin/sage
import hashlib
import re
with open("flag.txt", "rb") as f:
FLAG = f.read()
assert re.match(rb"Hero{[0-9a-zA-Z_]{90}}", FLAG)
F = FiniteField(2**256 - 189)
R = PolynomialRing(F, "x")
H = lambda n: int(hashlib.sha256(n).hexdigest(), 16)
C = lambda x: [H(x[i : i + 4]) for i in range(0, len(FLAG), 4)]
f = R(C(FLAG))
points = []
for _ in range(f.degree()):
r = F.random_element()
points.append([r, f(r)])
print(points)
flag = input(">").encode().ljust(len(FLAG))
g = R(C(flag))
for p in points:
if g(p[0]) != p[1]:
print("Wrong flag!")
break
else:
print("Congrats!")

View File

@ -0,0 +1,6 @@
#! /bin/sh
while :
do
socat TCP-LISTEN:${LISTEN_PORT},forever,reuseaddr,fork EXEC:'/home/sage/chall.sage'
done