出题脚本
密文flag
ZNpjDckEhgOPDHBmMhKYQ+tMzVV/EMe4W+oLoWKWqvQ
公钥pubkey.pem
-----BEGIN PUBLIC KEY-----
MDowDQYJKoZIhvcNAQEBBQADKQAwJgIhAMJjauXD2OQ/+5erCQKPGqxsC/bNPXDr
yigb/+l/vjDdAgEC
-----END PUBLIC KEY-----
解密脚本
from Crypto.PublicKey import RSA
import libnum
import gmpy2
with open("pubkey.pem","rb") as f:
key = RSA.import_key(f.read())
n =key.n
e =key.e
with open("flag","rb") as f:
c=libnum.s2n(f.read())
print(n)
print(e)
p=275127860351348928173285174381581152299
q=319576316814478949870590164193048041239
inv_p = gmpy2.invert(p, q)
inv_q = gmpy2.invert(q, p)
mp = pow(c, (p + 1) // 4, p)
mq = pow(c, (q + 1) // 4, q)
a = (inv_p * p * mq + inv_q * q * mp) % n
b = n - int(a)
c = (inv_p * p * mq - inv_q * q * mp) % n
d = n - int(c)
aa=[a,b,c,d]
for i in aa:
print(libnum.n2s(int(i)))