]> git.somenet.org - pub/jan/ctf-seminar.git/blob - writeups/icecrax/asis2019/why_better_libraries.py
Add Bit Game exploit
[pub/jan/ctf-seminar.git] / writeups / icecrax / asis2019 / why_better_libraries.py
1 import random
2 from Crypto.Util.number import *
3 p = 2150
4 H = 2314
5 pkey = 892 # found through find_pkey()  pkey^2 ≡ H (mod p) holds
6 c = 1353
7 t = 517
8 s = 483 # found through find_s() 
9
10 def find_s():
11     for k in range(1000):
12         s = ((c - t) * pkey + p * k) / H
13         if(s == int(round(s))):
14             print(s)
15
16 def find_pkey():
17     for i in range (1000):
18         if H % p == i**2 % p:
19             print(i)
20
21 # Tests:
22 print((c-t) % p == s * pkey % p)
23 print((c-t) * inverse(pkey,p) % p == s % p)
24 print((c-t) * inverse(pkey,p) % p)
25 print(s % p)
26 print(math.gcd(pkey, p))