[https://github.com/Simrantiwarii/RSA-ENCYRPTION/blob/1e88b32c9d1e133886f73115374d5018d946f5b8/Untitled6.ipynb] Can someone please look into this code and tell me why is it giving this error:
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'
I am trying to study the nature of encryption key component 'e' in RSA.
as the error message says: a is not a number but None. I assume that generatenextPrime(E)
returns 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
try this instead
def generatenextPrime(num):
e = num
while not is_prime(e):
e += 1
return e