欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 焦点 > rsarsa-给定pqe求私钥对密文解密

rsarsa-给定pqe求私钥对密文解密

2025/1/16 10:42:41 来源:https://blog.csdn.net/m0_51744133/article/details/145028806  浏览:    关键词:rsarsa-给定pqe求私钥对密文解密

题目:

Math is cool! Use the RSA algorithm to decode the secret message, c, p, q, and e are parameters for the RSA algorithm.p =  9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q =  11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e =  65537
c =  83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034Use RSA to find the secret message

根据RSA原理,e为公钥指数,pq为两个大素数,c在密码学里一般指密文。

通过pqe计算出私钥d,然后根据公式m=cdmod(n)求明文m,n为pq的乘积。

私钥d和e满足e*d≡1(modφ(n)),φ(n)是(p-1)*(q-1)

编写Python脚本:

from sympy import mod_inverse# 给定的参数
p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
e = 65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034# 计算 n 和 φ(n)
n = p * q
phi_n = (p - 1) * (q - 1)# 计算私钥 d
d = mod_inverse(e, phi_n)# 使用私钥 d 解密
m = pow(c, d, n)# 输出解密后的消息 
message = str(m)
print("解密后的消息:", message)

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com