I am currently using the PyCrypto library in order to implement ElGamal encryption for an academic assignment and I am getting the following error:
OverflowError: cannot fit 'int' into an index-sized integer
from Crypto import Random
from Crypto.Random import random
from Crypto.PublicKey import ElGamal
from Crypto.Util.number import GCD
message = "Hello!"
key = ElGamal.generate(1024, Random.new().read)
while 1:
k = random.StrongRandom().randint(1, key.p - 1)
if GCD(k, key.p - 1) == 1:
break
h = key.encrypt(message, k)
d = key.decrypt(h)
print(d)
I am not sure if I am reading the documentation incorrectly but I am basing it around this page:
If anybody has any code examples of the proper implementation I would appreciate it.