ElGamal Encryption in Python
From-scratch Python implementation of the ElGamal public-key encryption scheme over a prime-order multiplicative group, with key generation, encryption, and decryption end-to-end.
Sep 2022 - Dec 2022 • 3 months
Tech Stack
PythonNumber TheoryCryptography
Summary
ElGamal encryption gets its security from the discrete logarithm problem in cyclic groups. This implementation walks through:
- Safe-prime selection and generator finding
- Key generation (private exponent and public element)
- Probabilistic encryption with a fresh ephemeral randomness per message
- Decryption via modular inverse
Used as a teaching aid for understanding probabilistic public-key encryption before moving on to ECC and lattice-based schemes.