ElGamal explained in plain terms means understanding how a message can be locked with a key the whole world is allowed to see, and unlocked only by the one person who holds the matching secret. The central question is how two strangers can share a secret over a channel anyone can listen to, and the answer is the discrete logarithm: a piece of arithmetic that is easy in one direction and, as far as anyone knows, practically impossible in the other.
ElGamal is a public-key cryptosystem, published by Taher Elgamal in 1985, that encrypts messages and creates digital signatures using the difficulty of the discrete logarithm problem. Anyone can encrypt with the public key, but only the private key holder can decrypt.
The story starts in the mid-1980s, when public-key cryptography was barely a decade old. This article tells that story, explains what ElGamal is, how it works, and where it is used.
Key takeaways
- ElGamal is a public-key system based on the discrete logarithm problem.
- Anyone can encrypt with the public key; only the private key decrypts.
- The same mathematics also produces digital signatures.
- Each encryption uses fresh randomness, so the same message never looks twice alike.
- It is the encryption behind PGP and GnuPG private email.
What ElGamal is
The system begins with a large prime number and a generator, a number whose powers cycle through the group. The private key is a secret number chosen at random, and the public key is the generator raised to that secret power, published openly, so anyone can use it to encrypt a message for its owner.
The security rests on a simple asymmetry. Raising a number to a power modulo a large prime is fast, but working backwards, finding the exponent from the result, is the discrete logarithm problem, and for a well-chosen prime of a few thousand bits, no known method can solve it in any reasonable time. That gap, easy one way and hard the other, is the whole foundation of the system.
Taher Elgamal published the system in 1985, building directly on the Diffie-Hellman key exchange of 1976. Where Diffie and Hellman had shown two people could agree on a shared secret, Elgamal showed the same mathematics could encrypt a message outright, and his signature variant became the basis for the Digital Signature Standard. Our guide to asymmetric encryption explains the family ElGamal belongs to, and our guide to public key infrastructure explains how such keys are distributed and trusted.
How ElGamal works
Encrypting a message starts with the recipient’s public key and a fresh random number, chosen anew for every single message. The sender computes two values from that random number and the public key, and sends both to the recipient, who combines them with the private key to recover the original message.
The two values are the point of the design. The first is the generator raised to the random number, which lets the recipient reconstruct the shared secret, and the second is the message multiplied by the public key raised to the same random number, which hides it. Only the private key can undo that multiplication, because only it can compute the shared secret from the first value.
The fresh randomness matters more than it looks. Because a new random number is used every time, encrypting the same message twice produces two completely different ciphertexts, which means an eavesdropper cannot tell whether two messages are the same, and cannot learn anything by comparing them. The cost is that each ciphertext is twice the size of the message, which is why ElGamal is rarely used to encrypt large files directly.
Signing works on the same foundation with the roles reversed. The signer uses the private key and a random number to produce a pair of numbers that anyone can check against the public key, and the check proves the message came from the key holder and has not been changed. The Digital Signature Algorithm, DSA, is a direct descendant of this signature scheme, standardised by the US government in the 1990s.
ElGamal has one more property that surprises people: it is homomorphic, in a limited sense. Multiplying two ElGamal ciphertexts gives an encryption of the product of the two messages, which means computations can be done on encrypted data without decrypting it first. That property, little used in 1985, is now one of the reasons cryptographers keep coming back to the system.

Comparing ElGamal with other public-key systems
ElGamal is one of several ways to do public-key cryptography, and each was built with a different emphasis. RSA is older and simpler to use, elliptic curve cryptography does the same job with far smaller keys, and the newest lattice systems are designed to survive quantum computers, and each approach trades key size for speed and trust in a different way.
The table below sets out the main contrasts between the leading approaches.
| Aspect | ElGamal | RSA | Elliptic curve |
|---|---|---|---|
| Hard problem | Discrete logarithm | Factoring large numbers | Elliptic curve discrete log |
| Key size | Large, thousands of bits | Large, thousands of bits | Small, hundreds of bits |
| Randomised encryption | Yes, every time | Only with padding | Depends on the scheme |
| Signatures | Yes, native | Yes, native | Yes, native |
| Best for | Encrypted email, voting | General purpose | Phones and small devices |
The practical result is that ElGamal is the right choice where randomised encryption and homomorphic properties matter, RSA suits general-purpose use, and elliptic curves fit devices where key size and speed are precious.
Where ElGamal is used
Encrypted email is ElGamal’s most famous home. Pretty Good Privacy, PGP, and its open version GnuPG use ElGamal keys to encrypt mail, and because each message uses fresh randomness, two identical emails sent to the same person look completely different on the wire.
Electronic voting uses ElGamal for its homomorphic property. A vote can be encrypted, the encrypted votes can be added together without decrypting any of them, and only the final total is decrypted, which means the count is public and verifiable while every individual vote stays secret.
Digital signatures in government systems descend from ElGamal. The Digital Signature Algorithm, DSA, standardised by NIST, is a variant of ElGamal’s signature scheme, and it was the standard signature method in US government systems for years before elliptic curve signatures took over.
Secure messaging research keeps returning to ElGamal. Its randomised encryption makes it a natural fit for systems that must hide patterns in traffic, and its homomorphic property makes it useful for protocols that compute on encrypted data, from private auctions to privacy-preserving statistics.
Hybrid encryption systems use ElGamal as the key-wrapping layer. A random symmetric key is encrypted with ElGamal and sent alongside a message encrypted with that symmetric key, which combines ElGamal’s public-key convenience with the speed of symmetric encryption for the bulk of the data.
Strengths and limits
The greatest strength of ElGamal is its randomness. Every encryption is different, even for the same message, which removes a whole class of attacks that work against deterministic systems, and the homomorphic property opens doors that RSA simply cannot.
It is also a strength that the system is simple to understand and to prove secure. The security reduces cleanly to the discrete logarithm problem, which has been studied for decades, so the trust in ElGamal rests on a problem cryptographers know well rather than on a new and untested idea.
The limits are real, though. Ciphertexts are twice the size of the message, keys are large, and a quantum computer running Shor’s algorithm would break the discrete logarithm problem entirely. For most new systems, elliptic curve cryptography offers the same security with far smaller keys, and ElGamal survives where its special properties are needed.
ElGamal checklist
- Use ElGamal where randomised encryption is a requirement, not a bonus.
- Generate a fresh random number for every single encryption.
- Use a large, well-chosen prime; small groups are easy to break.
- Never reuse the random number in signatures; it leaks the private key.
- Use hybrid encryption for large data; ElGamal alone doubles the size.
- Prefer elliptic curves for new systems where key size matters.
- Remember a quantum computer would break the discrete logarithm.
- Verify signatures against the public key before trusting a message.
- Keep the private key offline; the whole system rests on it.
Frequently asked questions
What is ElGamal in simple terms?
It is a public-key system where anyone can lock a message with the public key, only the private key holder can unlock it, and every encryption looks different because of fresh randomness.
Who invented ElGamal?
Taher Elgamal, who published the system in 1985, building on the Diffie-Hellman key exchange of 1976.
What is the discrete logarithm problem?
It is the problem of finding the exponent that produced a given result when raising a number to a power modulo a large prime, which is easy in one direction and extremely hard in reverse.
Why are ElGamal ciphertexts twice the size of the message?
Because each encryption sends two values, one to reconstruct the shared secret and one carrying the hidden message, and both are needed to decrypt.
Is ElGamal still used today?
Yes, in PGP and GnuPG encrypted email, in electronic voting, and in research systems that need its homomorphic property, though elliptic curves dominate new designs.
When should I not use ElGamal?
When key size or ciphertext size matters, when the data is large, or when quantum resistance is required, where elliptic curves or lattice systems fit better.
The bottom line
ElGamal explained in one line is this: raise a generator to a secret power for the public key, and let fresh randomness make every encryption unique.
It is the system that turned Diffie-Hellman mathematics into real encrypted email, and the reason a message can be locked for one person in a room full of listeners.
This article is general information about how ElGamal works, not advice about choosing encryption for a particular system.







