计算RSA公钥和私钥时
幂是一个大数,而四舍五入的结果是长整数也是错误的
from fractions import gcd
def doLoop(e, totient):
v = 0
i = 1
x = 0
vv = 0
while vv == 0:
x = (e * i - 1) % totient
if x == 0:
v = i
vv = 1
i = i + 1
return v
primeX = 3
primeY = 11
n = primeX*primeY
totient = (primeX - 1) * (primeY - 1)
e = 17
privatekey = doLoop(e, totient)
m = 9
encryptedvalue = int(int(math.pow(m,e)) % n)
int(math.pow(encryptedvalue,privatekey)) % n
>>> m
9
>>> e
17
>>> n
33
>>> int(math.pow(m,e)) % n
14L
应该是15到14岁
长整数错误
>>> int(round(math.pow(m,e)))
16677181699666568L
舍入数也是错误的
应该是
16677181699666569
可以确认。。。但这里有一些解决办法。。你知道吗
相关问题 更多 >
编程相关推荐