1.已知p,q,e,求d
(1)求n = p * q
(2)求 phin = (p - 1) * (q - 1) #因为p,q为质数
(3)由于 gcd(e,φ(n))=1(可以用assert(1 == gcd(e, phin))进行判断) 且 e * d = 1 mod φ(n) ,可用pow,d = pow(e, -1, phin) #d称作e在φ(n)模下的逆元(模反元素),d = pow(e, -1, phin) 代表 e * d = 1 mod φ(n)(只适用于同余于1的情况)
2. 已知p,q,e,c,求m
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
(1)与上题类似,在求出d后,运用m = c ** d(mod n) 可求,即 m = pow(c, d, n)