Classical Cryptography Simulator

ElGamal Cryptosystem - Detailed Number Operations

Comprehensive ElGamal public-key cryptosystem simulation with detailed mathematical steps. Work with numbers only to understand discrete logarithm problems and modular arithmetic.

Key Generation with Detailed Steps
Generate public and private keys with complete mathematical verification
Encryption with Detailed Steps
Encrypt a numeric message using the recipient's public key
Decryption with Detailed Steps
Decrypt the ciphertext using your private key
Control Panel
ElGamal Mathematical Foundation
Complete mathematical formulation

Key Generation

1. Choose large prime p
2. Find primitive root g of p
3. Choose private key x ∈ [1, p-2]
4. Calculate public key y = g^x mod p
5. Public key: (p, g, y)
6. Private key: x

Encryption

1. Choose random k ∈ [1, p-2]
2. Calculate c₁ = g^k mod p
3. Calculate c₂ = m × y^k mod p
4. Ciphertext: (c₁, c₂)

Decryption

1. Calculate s = c₁^x mod p
2. Find s^(-1) mod p
3. Calculate m = c₂ × s^(-1) mod p
4. Recover original message m
Security Analysis
Understanding the security properties

Discrete Logarithm Problem

Given y = g^x mod p, finding x is computationally hard

Diffie-Hellman Problem

Given g^x mod p and g^k mod p, finding g^(xk) mod p is hard

Probabilistic Encryption

Same message produces different ciphertexts due to random k

Semantic Security

Ciphertext reveals no information about plaintext

Key Security Considerations

• Prime p should be at least 2048 bits
• Random k must be unique for each encryption
• Private key x must remain secret
• Generator g must be a primitive root
Practical Applications & Examples
Real-world usage and numerical examples

Digital Signatures

  • • DSA (Digital Signature Algorithm)
  • • Based on ElGamal signature scheme
  • • Used in PKI and certificates

Key Exchange

  • • Diffie-Hellman key exchange
  • • TLS/SSL handshake protocols
  • • Secure channel establishment

Research Areas

  • • Homomorphic encryption
  • • Electronic voting systems
  • • Cryptographic protocols

Example with Small Numbers:

Let p = 23, g = 5 (primitive root)
Private key x = 6
Public key y = 5^6 mod 23 = 8
Message m = 15, Random k = 3
c₁ = 5^3 mod 23 = 10
c₂ = 15 × 8^3 mod 23 = 15 × 6 mod 23 = 21
Ciphertext: (10, 21)
Decryption: s = 10^6 mod 23 = 8
m = 21 × 8^(-1) mod 23 = 21 × 3 mod 23 = 15 ✓