rsarsa题解

简介: rsarsa题解

rsarsa题解


rsa算法说明

RSA加密算法_光无影的博客-CSDN博客

本题所给的信息

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 =  83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
Use RSA to find the secret message

解题过程

可知题目中给了p,q,e和密文c

可以求出e的逆元素d,模数p*q

得到密钥d,n

根据解密公式可以调用powmod进行解密

import gmpy2
E = 65537
c = 83208298995174604174773590298203639360540024871256126892889661345742403314929861939100492666605647316646576486526217457006376842280869728581726746401583705899941768214138742259689334840735633553053887641847651173776251820293087212885670180367406807406765923638973161375817392737747832762751690104423869019034
p = 9648423029010515676590551740010426534945737639235739800643989352039852507298491399561035009163427050370107570733633350911691280297777160200625281665378483
q = 11874843837980297032092405848653656852760910154543380907650040190704283358909208578251063047732443992230647903887510065547947313543299303261986053486569407
N=p*q
D = int(gmpy2.invert(E,(p-1)*(q-1)))  
#求逆元
message =gmpy2.powmod(c,D,N)
#使用密钥解密
print(message)


相关文章
|
6月前
leetcode209题解
leetcode209题解
35 0
Leetcode contests 93 题解
870. Advantage Shuffle 起始就是hdoj 1502田忌赛马,但要求的结果不一样而已。这里我用了个pair来记录B中每个数字对应的位置。
48 0
|
数据安全/隐私保护
[FlareOn5]FLEGGO 题解
[FlareOn5]FLEGGO 题解
61 1
|
数据安全/隐私保护
[UTCTF2020]babymips 题解
[UTCTF2020]babymips 题解
87 1
|
数据安全/隐私保护
CrackRTF 题解
CrackRTF 题解
70 0
|
数据安全/隐私保护
[FlareOn6]Overlong 题解
[FlareOn6]Overlong 题解
99 0
Leetcode contests 95 题解
用容斥原理可以计算出一个数字Num之下有多少个A或B的倍数cnt,我们从最大值二分这个数字Num,拿cnt和N做比较来决定二分的走向,最终l和r肯定会收敛到一起,这就是我们要的结果了。 这道题的数值范围不是特别大 ,用long就可以完全满足需求了。
25 0
|
Go 数据安全/隐私保护
世上无难事题解
世上无难事题解
92 0
世上无难事题解