ELGAMAL ENCRYPTION

Key generation:
1. Choose prime p and generator g (p = 23, g = 5).
2. Choose private key x (6).
3. Public key y = g^x mod p = 5^6 mod 23 = 8.

Encryption (message m, random k):
    c1 = g^k mod p
    c2 = m * y^k mod p
    cipher = (c1, c2)

Decryption:
    s  = c1^x mod p
    m  = c2 * s^-1 mod p

Example: m = 10, k = 3
c1 = 5^3 mod 23 = 10
c2 = 10 * 8^3 mod 23 = 10 * 6 mod 23 = 14
s = 10^6 mod 23 = 6, s^-1 = 4 (6*4 = 24 = 1 mod 23), m = 14*4 mod 23 = 10.
Security depends on the discrete logarithm problem.
