Having already looked a few months ago at RSA, it’s time to kick the tyres on a ElGamal example of public key encryption. Like the last example, in this article I want to focus on the bare nuts and bolts - that is how it works on a mathematical level.
ElGamal security is based on the Discrete Log Problem, which is what we call a very hard problem to solve. Loosely it’s …
##Elgamal Theory in 3 steps
###1. Key Generation
Generate a key-pair as follows:
- Select a large random prime p and a generator α of Z∗p
- Generate a random integer x such that 1≤x≤p−2
-
Compute
y = αxmod p
- public key is (p, α, y)
- private key is x
2. Encryption
Given a message m such that 0 ≤ m < p, any user B can encrypt m as follows:
- Pick the integer k ∈ {1..p−2} uniformly at random.
-
Compute c1 - the first component of the ciphertext
c1 = αk mod p
-
Compute c2 - the second component of the ciphertext
c2 =m×yk (mod p)
- The ciphertext is the pair (c1, c2)
3. Decryption
A can decrypt (c1, c2) as follows:
-
Compute m - the original message
m = (cp−1−x) × c (mod p)