已知c,e,n,dp 求m(dp=d%(p-1))标签:tmp,gmpy2,求解,rsa,print,import,泄露,dp From: https://www.cnblogs.com/shadowkillnet/p/17754383.html
import gmpy2
from Crypto.Util.number import *
n =
dp =
c =
e =
tmp = e * dp -1
#根据联立条件有: e*dp = 1 + k(p-1),故求解p的式子为:(p-1) = (e*dp-1) / k
for k in range(1, e):#因为K上限只到e,故遍历求解
if tmp % k == 0:#验证(p-1)是否为整除结果
p = (tmp // k) + 1
if n % p == 0:#验证p能否被n整除
q = n // p
if gmpy2.is_prime(p) and gmpy2.is_prime(q):#验证求解的p, q是否为素数
# print(k)
print("N的分解结果为 : ")
print("%d = %d * %d" % (n, p, q))
break
phi = (p-1)*(q-1)
d=gmpy2.invert(e,phi)
m=gmpy2.powmod(c,d,n)
print(long_to_bytes(m))