ElGamal Encryption Algorithm Program in C

The ElGamal encryption is a symmetric key encryption algorithm for private-key cryptography which is based on the public key exchange and provides an additional layer of security by asymmetrically encrypting keys previously used for asymmetric message encryption. 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 scope of this article. We suggest to go through very simple explanation given on Wikipedia for detailed explanation.
 

 
Following is the implementation of 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.

 

 

 
Above program is tested in Windows environment using Code::Blocks 16.01.

 
Thanks for reading.

Please use our online compiler to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
newest oldest most voted
Notify of
Shashank
Guest

This doesn’t work.