A Python3 implementation of ElGamal encryption algorithm.
Here is the wikipedia page of the algorithm where you can find an explanation on how this algorithm work.
alice = Elgamal()
alice_public_key = alice.publishPublicKey()
message = "Hello World !"
bob = Elgamal()
bob_cipher = bob.cipher(alice_public_key, message)
alice_decrypted = alice.unCipher(bob_cipher)
The problem of discrete logartihm is NP-Complete, but if the random x picked is to small we can possibly guess the secret key in a reasonnable time. Worth give it a try !
attackElGamal(public_key)
This implementaton is protected against Quadratic Residual attacks.