The ElGamal encryption is an asymmetric key encryption algorithm for public-key cryptography, which is based on the Diffie–Hellman key exchange. It can be defined over any cyclic group G. Its security depends upon the difficulty of a certain problem in G related to computing discrete logarithms.

ElGamal encryption consists of three components: the key generator, the encryption algorithm, and the decryption algorithm. These operations are out of the scope of this article. We suggest going through the simple explanation given on Wikipedia for a detailed explanation.

 
Implementation:

Following is the implementation of the ElGamal encryption algorithm in C. The program expects an input file, plain.txt, which contains the plain text, and generates an output file, results.txt, which contains our decrypted text. The program also generates two intermediary files – cipher1.txt and cipher2.txt.

 
The above program is tested in the Windows environment using Code::Blocks 16.01.

That’s all about ElGamal Encryption algorithm implementation in C.