Asymmetric cipher  |  Discrete logarithm  |  1024 • 2048 • 3072 • 4096-bit  |  Probabilistic encryption

ElGamal Encryption

Generate ElGamal key pairs, encrypt and decrypt messages using the discrete logarithm asymmetric cipher. A probabilistic public-key encryption scheme based on Diffie-Hellman — the same plaintext encrypted twice always produces different ciphertexts.

1
Generate ElGamal Key Pair
Choose a key length and generate a public / private key pair

2
Encrypt with Public Key
Encrypt a message using the ElGamal public key (probabilistic — each encryption produces a unique ciphertext)
Public key auto-filled from Step 1. Enter your message and click Encrypt.

3
Decrypt with Private Key
Recover the original message using the ElGamal private key
Cipher text and private key auto-filled. Click Decrypt to recover your message.

ElGamal Encryption: A Comprehensive Guide

Introduced in 1985 by Taher ElGamal, ElGamal encryption is an asymmetric cryptosystem built on the Discrete Logarithm Problem (DLP) — an extension of the Diffie-Hellman key exchange. It is probabilistic: encrypting the same plaintext twice with the same public key always produces different ciphertexts, providing strong resistance to chosen-plaintext attacks.

Key Components

ComponentDescription
Public Parametersp (large prime), g (generator mod p)
Public Keyh = gx mod p
Private Keyx (secret exponent, 1 < x < p-1)
Ciphertext size2× plaintext size (probabilistic overhead)

Security Parameters (2025)

Key lengthSecurity levelStatus
1024-bit~80-bitDeprecated — do not use
2048-bit~112-bitAcceptable until 2030
3072-bit~128-bitRecommended
4096-bit~140-bitHigh security

Encryption Process

  1. Pick a random ephemeral key k (1 < k < p-1)
  2. Compute c1 = gk mod p
  3. Compute c2 = m × hk mod p
  4. Ciphertext is the pair (c1, c2)

Decryption Process

  1. Compute s = c1x mod p (shared secret)
  2. Recover message: m = c2 × s-1 mod p

ElGamal vs RSA

PropertyElGamalRSA
Security basisDiscrete logarithmInteger factorization
Deterministic?No (probabilistic)Yes (with PKCS padding)
Ciphertext size2× plaintextSame as key size
SpeedSlower (two exponentiations)Faster decryption
Quantum resistanceNo (Shor's algorithm)No (Shor's algorithm)

References

  1. T. ElGamal, "A Public Key Cryptosystem and a Signature Scheme Based on Discrete Logarithms" (1985)
  2. NIST SP 800-57: Recommendation for Key Management
  3. ElGamal encryption on Wikipedia