-
Notifications
You must be signed in to change notification settings - Fork 4
/
solve.py
38 lines (26 loc) · 1.21 KB
/
solve.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
#!/usr/bin/env python3
from Crypto.Util.number import isPrime
from Crypto.PublicKey import RSA
from gmpy2 import iroot
c = 4881495507745813082308282986718149515999022572229780274224400469722585868147852608187509420010185039618775981404400401792885121498931245511345550975906095728230775307758109150488484338848321930294974674504775451613333664851564381516108124030753196722125755223318280818682830523620259537479611172718588812979116127220273108594966911232629219195957347063537672749158765130948724281974252007489981278474243333628204092770981850816536671234821284093955702677837464584916991535090769911997642606614464990834915992346639919961494157328623213393722370119570740146804362651976343633725091450303521253550650219753876236656017
with open('key') as f:
key = RSA.import_key(f.read())
n = key.n
e = key.e
def get_next_prime(prime: int) -> int:
test = prime + 2
while not isPrime(test):
test += 2
return test
while True:
p, _ = iroot(n, 2)
while not isPrime(p):
p -= 2
q = get_next_prime(p)
n = p * q
phi_n = (p - 1) * (q - 1)
d = pow(e, -1, phi_n)
p = pow(c, d, n)
if b'SEE{'.hex() in hex(p):
print(bytes.fromhex(hex(p)[2:]).decode())
break