Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@theoremoon
Created October 11, 2020 01:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theoremoon/8969384409b95a90eb5769045a270b90 to your computer and use it in GitHub Desktop.
Save theoremoon/8969384409b95a90eb5769045a270b90 to your computer and use it in GitHub Desktop.
SECCON 2020 Online CTF - solution for koharu
with open("output.txt") as f:
line = f.readline()
p = int(line.split("=")[1])
PR.<x> = PolynomialRing(GF(p))
PQ = sage_eval(f.readline().split("=")[1], locals={'x': x})
f.readline() # pass R
c = sage_eval(f.readline().split("=")[1], locals={'x': x})
pq = factor(PQ)
P = pq[0][0]
Q = pq[1][0]
print(P)
print(Q)
NP = p ** P.degree()
NQ = p ** Q.degree()
m = ""
from tqdm import tqdm
for f in tqdm(c):
if power_mod(f, (NP-1)//2, P) == 1 and power_mod(f, (NQ-1)//2, Q) == 1:
m += "1"
else:
m += "0"
m = int(m[::-1],2 )
print(bytes.fromhex(hex(m)[2:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment