From 9e8502081cb418ff034cdbc7ef836f5a87088dba Mon Sep 17 00:00:00 2001 From: agatha Date: Fri, 25 Oct 2024 16:23:41 -0400 Subject: [PATCH] crypto: interpolation --- crypto/interpolation/interpolation.zip | Bin 0 -> 1377 bytes crypto/interpolation/interpolation/Dockerfile | 11 +++++++ crypto/interpolation/interpolation/chall.sage | 31 ++++++++++++++++++ crypto/interpolation/interpolation/entry.sh | 6 ++++ 4 files changed, 48 insertions(+) create mode 100644 crypto/interpolation/interpolation.zip create mode 100644 crypto/interpolation/interpolation/Dockerfile create mode 100755 crypto/interpolation/interpolation/chall.sage create mode 100644 crypto/interpolation/interpolation/entry.sh diff --git a/crypto/interpolation/interpolation.zip b/crypto/interpolation/interpolation.zip new file mode 100644 index 0000000000000000000000000000000000000000..7ba3e64aad51724bc892bab2e531a2c0db7cf281 GIT binary patch literal 1377 zcmWIWW@h1H00F@j;gMhll;C5KVaUuYNi8bK&q*xF%+J#g4dG;9zT_^Mein#JE4UdL zSza(RFo1~wpgAHyog83uj&6E6dmfN?9Ec?_%yG$2&Q2{#%gjlIn+P%$%|zF}i(E|x z60PsQi`Wa@vs|yjv5Sj&;Wk5Y6+y#i1&vmjlPA2mJG-@{{D;N!$8RicnABX)=~Ho|DUnJn6cG#UN*87>0jS^Gb>;^@=m_`8GH#7 zp)zUh1F46va+a=}KXLx-Rq=CX%v&{o&cqp$7qcg=V(vZX{gjCT)#=CX9pj(H$iPs{ zge|I)GZJ%h^okSH@kdplW8Q58fjyr^v%fkmGsJN{Ja&ENidy7(pUnu9kQP55rT>R|6(_H4Vk`S$tm5;vHp#Jb4}hYu=up` zfkr>ZPkHXWv! z?a3CG-%qk;DV|-={j}z@_u02svz3;Xe==98-+U*>%lyKpg%QEOjxzHcT{h?Sfb_$A2dBnTs#r=9?6UOvITPywd#vPpy70(#p&B!Fjj4Ojn0Fx^S2r#^L1kvc( zofVSZ(K05)Ok9~AVkR&_F)V5Hz%Uaz>l0@>YSuzF-2!L{s*4dBjX1MW(>}uNw~e1M a%tp=$xJ+kd1BD_B5as~&-v^eB3=9C-n()d1 literal 0 HcmV?d00001 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