这段代码是否会给我正确的 RSA 密钥值(假设其他函数是正确的)?我无法让我的程序正确解密,因为某些块没有正确解密
这是在python中:
import random
def keygen(bits):
p = q = 3
while p == q:
p = random.randint(2**(bits/2-2),2**(bits/2))
q = random.randint(2**(bits/2-2),2**(bits/2))
p += not(p&1) # changes the values from
q += not(q&1) # even to odd
while MillerRabin(p) == False: # checks for primality
p -= 2
while MillerRabin(q) == False:
q -= 2
n = p * q
tot = (p-1) * (q-1)
e = tot
while gcd(tot,e) != 1:
e = random.randint(3,tot-1)
d = getd(tot,e) # gets the multiplicative inverse
while d<0: # i can probably replace this with mod
d = d + tot
return e,d,n
生成一组密钥:
e = 3daf16a37799d3b2c951c9baab30ad2d
d = 16873c0dd2825b2e8e6c2c68da3a5e25
n = dc2a732d64b83816a99448a2c2077ced