Diffie–Hellman key exchange lets two participants derive the same secret while sharing only public values. Each chooses a private exponent, publishes its modular exponentiation, and combines the received value with its own private exponent. section 8.3.1
The exchange proceeds as follows:
- Agree on a prime p and generator g. section 8.3.1
- Choose private exponents a and b, then publish A = gᵃ mod p and B = gᵇ mod p. section 8.3.1
- Compute S = Aᵇ mod p = Bᵃ mod p = gᵃᵇ mod p. section 8.3.1
- Rely on the difficulty of recovering a private exponent from a public value: the discrete logarithm problem. section 8.3.1
A small modular example
Using p = 13 and g = 7, Alice chooses a = 3 and publishes A = 5. Bob chooses b = 9 and publishes B = 8. Alice computes 8³ mod 13 = 5; Bob computes 5⁹ mod 13 = 5. Both obtain the shared secret S = 5, while an eavesdropper sees only the public values. section 8.3.1
Table 8.1 Exponentiation table for multiplicative group modulo 13
| Base \ Exponent (n) | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| \(1^n \bmod 13\) | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| \(2^n \bmod 13\) | 1 | 2 | 4 | 8 | 3 | 6 | 12 | 11 | 9 | 5 | 10 | 7 | 1 |
| \(3^n \bmod 13\) | 1 | 3 | 9 | 1 | 3 | 9 | 1 | 3 | 9 | 1 | 3 | 9 | 1 |
| \(4^n \bmod 13\) | 1 | 4 | 3 | 12 | 9 | 10 | 1 | 4 | 3 | 12 | 9 | 10 | 1 |
| \(5^n \bmod 13\) | 1 | 5 | 12 | 8 | 1 | 5 | 12 | 8 | 1 | 5 | 12 | 8 | 1 |
| \(6^n \bmod 13\) | 1 | 6 | 10 | 8 | 9 | 2 | 12 | 7 | 3 | 5 | 4 | 11 | 1 |
| \(7^n \bmod 13\) | 1 | 7 | 10 | 5 | 9 | 11 | 12 | 6 | 3 | 8 | 4 | 2 | 1 |
| \(8^n \bmod 13\) | 1 | 8 | 12 | 5 | 1 | 8 | 12 | 5 | 1 | 8 | 12 | 5 | 1 |
| \(9^n \bmod 13\) | 1 | 9 | 3 | 1 | 9 | 3 | 1 | 9 | 3 | 1 | 9 | 3 | 1 |
| \(10^n \bmod 13\) | 1 | 10 | 9 | 12 | 3 | 4 | 1 | 10 | 9 | 12 | 3 | 4 | 1 |
| \(11^n \bmod 13\) | 1 | 11 | 4 | 5 | 3 | 7 | 12 | 2 | 9 | 8 | 6 | 10 | 1 |
| \(12^n \bmod 13\) | 1 | 12 | 1 | 12 | 1 | 12 | 1 | 12 | 1 | 12 | 1 | 12 | 1 |
Use the exponentiation table to verify the public values and shared-secret calculations modulo 13. section 8.3.1



