crypto: interpolation
This commit is contained in:
parent
6013199f17
commit
9e8502081c
BIN
crypto/interpolation/interpolation.zip
Normal file
BIN
crypto/interpolation/interpolation.zip
Normal file
Binary file not shown.
11
crypto/interpolation/interpolation/Dockerfile
Normal file
11
crypto/interpolation/interpolation/Dockerfile
Normal 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"]
|
31
crypto/interpolation/interpolation/chall.sage
Executable file
31
crypto/interpolation/interpolation/chall.sage
Executable 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!")
|
6
crypto/interpolation/interpolation/entry.sh
Normal file
6
crypto/interpolation/interpolation/entry.sh
Normal file
@ -0,0 +1,6 @@
|
||||
#! /bin/sh
|
||||
|
||||
while :
|
||||
do
|
||||
socat TCP-LISTEN:${LISTEN_PORT},forever,reuseaddr,fork EXEC:'/home/sage/chall.sage'
|
||||
done
|
Loading…
Reference in New Issue
Block a user