diff --git a/crypto/interpolation/interpolation.zip b/crypto/interpolation/interpolation.zip new file mode 100644 index 0000000..7ba3e64 Binary files /dev/null and b/crypto/interpolation/interpolation.zip differ diff --git a/crypto/interpolation/interpolation/Dockerfile b/crypto/interpolation/interpolation/Dockerfile new file mode 100644 index 0000000..b6c2536 --- /dev/null +++ b/crypto/interpolation/interpolation/Dockerfile @@ -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"] \ No newline at end of file diff --git a/crypto/interpolation/interpolation/chall.sage b/crypto/interpolation/interpolation/chall.sage new file mode 100755 index 0000000..d47069e --- /dev/null +++ b/crypto/interpolation/interpolation/chall.sage @@ -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!") diff --git a/crypto/interpolation/interpolation/entry.sh b/crypto/interpolation/interpolation/entry.sh new file mode 100644 index 0000000..15caf60 --- /dev/null +++ b/crypto/interpolation/interpolation/entry.sh @@ -0,0 +1,6 @@ +#! /bin/sh + +while : +do + socat TCP-LISTEN:${LISTEN_PORT},forever,reuseaddr,fork EXEC:'/home/sage/chall.sage' +done