题目给出public.key, flag.enc
如果n较小,可以尝试分解n来进行攻击
"""
需要安装2个模块:rsa,pycrypto
如果有问题,应该把之前安装的crypto、pycrypto模块卸载掉重新安装一遍
还需要使用 yafu 分解n
"""import rsa
from Crypto.PublicKey import RSAdef egcd(a, b):if a == 0:return (b, 0, 1)else:g, y, x = egcd(b % a, a)return (g, x - (b // a) * y, y)pub = RSA.importKey(open('pub.key').read())
n = long(pub.n)
e = long(pub.e)
if not p an not q:print 'Need get p,q'exit(0)d = egcd((p - 1) * (q - 1), e)[2]
if d <0:d &#43;&#61; (p - 1) * (q - 1)key &#61; RSA.construct((n, e, d))
key.exportKey()
open("private.pem", "w").write(key.exportKey())p &#61; open("private.pem").read()
privkey &#61; rsa.PrivateKey.load_pkcs1(p)
crypto &#61; open("flag.enc").read()
message &#61; rsa.decrypt(crypto, privkey)
print message