-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathsol.py
66 lines (46 loc) · 1.07 KB
/
sol.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from pwn import *
from subprocess import check_output
import sympy
from math import gcd
host = args.HOST or 'localhost'
port = args.PORT or 31538
if args.LOCAL:
r = process('python3 ./kotf.py', shell=True)
else:
r = remote(host, port)
r.recvuntil('proof of work: ')
r.sendafter('solution: ', check_output(r.recvline(), shell=True))
log.info('pow done')
A = open('mA', 'rb')
B = open('mB', 'rb')
a = A.read()
b = B.read()
p = int(r.recvline())
q = int(r.recvline())
g = int(r.recvline())
y = int(r.recvline())
r.recvline()
r.sendline(a.hex())
h1 = int(r.recvline())
r1 = int(r.recvline())
s1 = int(r.recvline())
r.recvline()
r.sendline(b.hex())
h2 = int(r.recvline())
r2 = int(r.recvline())
s2 = int(r.recvline())
r.recvline()
r.recvline()
r.recvline()
mhash = r.recvline()[12:]
ma = sympy.Matrix([[s1, q-r1], [s2, q-r2]])
mb = sympy.Matrix([h1, h2-s2])
det = int(ma.det())
ans = pow(det, q-2, q) * ma.adjugate() @ mb % q
x = ans[1]
k = 5
R = pow(g, k, p) % q
S = (pow(k, q - 2, q) * (int(mhash) + x * R)) % q
r.sendline(str(R))
r.sendline(str(S))
r.interactive()