-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathchall.sage.py
40 lines (29 loc) · 1.1 KB
/
chall.sage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# This file was *autogenerated* from the file chall.sage
from sage.all_cmdline import * # import sage library
_sage_const_2 = Integer(2); _sage_const_256 = Integer(256); _sage_const_189 = Integer(189); _sage_const_16 = Integer(16); _sage_const_4 = Integer(4); _sage_const_0 = Integer(0); _sage_const_1 = Integer(1)#!/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(_sage_const_2 **_sage_const_256 - _sage_const_189 )
R = PolynomialRing(F, "x")
H = lambda n: int(hashlib.sha256(n).hexdigest(), _sage_const_16 )
C = lambda x: [H(x[i : i + _sage_const_4 ]) for i in range(_sage_const_0 , len(FLAG), _sage_const_4 )]
f = R(C(FLAG))
points = []
for _ in range(f.degree()):
r = F.random_element()
points.append([r, f(r)])
print(points)
try:
flag = input(">").encode().ljust(len(FLAG))
g = R(C(flag))
for p in points:
if g(p[_sage_const_0 ]) != p[_sage_const_1 ]:
print("Wrong flag!")
break
else:
print("Congrats!")
except Exception:
pass