我的代码有一些错误,有人能帮我复习一下吗



[https://github.com/Simrantiwarii/RSA-ENCYRPTION/blob/1e88b32c9d1e133886f73115374d5018d946f5b8/Untitled6.ipynb]有人能看看这个代码,告诉我为什么会出现这个错误吗:

TypeError                                 Traceback (most recent call last)
<ipython-input-43-01ba3f5a9a3e> in <module>
88 
89 if __name__ == '__main__':
---> 90     public_key,private_key = generate_keyPairs()
91     print("Public: ",public_key)
92     print("Private: ",private_key)
<ipython-input-43-01ba3f5a9a3e> in generate_keyPairs()
53         E = generatenextPrime(E)
54         #print(type(F))
---> 55         g = gcd(E,phi)
56     #print("E=",E,)
57     #print(type(E))
<ipython-input-43-01ba3f5a9a3e> in gcd(a, b)
11 def gcd(a, b):
12     while b != 0:
---> 13         a, b = b, a % b
14     return a
15 
TypeError: unsupported operand type(s) for %: 'NoneType' and 'int'

我正在尝试研究RSA中加密密钥组件"e"的性质。

如错误消息所示:a不是数字,而是None。我假设generatenextPrime(E)返回None

def generatenextPrime(num):
E = num+1
#print ("E= %d" %E)
if is_prime(E):
return E
else:
num += 1  # <--- nothing (None) is returned in that case

试试这个

def generatenextPrime(num):
e = num
while not is_prime(e):
e += 1
return e

相关内容

  • 没有找到相关文章