EXERCISE 2 — Diffie-Hellman with real (small) numbers ====================================================== The real DH formula uses modular exponentiation: public = g^private mod p shared = (other side's public)^(my private) mod p PUBLIC parameters (agreed openly, an eavesdropper sees these): p = 23 (a small prime) g = 5 (the base / generator) PRIVATE choices (each side keeps secret): client private a = 6 server private b = 15 STEP 1 — each computes their PUBLIC value: client A = g^a mod p = 5^6 mod 23 = 15625 mod 23 = 8 server B = g^b mod p = 5^15 mod 23 = 30517578125 mod 23 = 19 -> client sends 8, server sends 19 (both travel in the open) STEP 2 — each computes the SHARED secret from the other's public value: client: B^a mod p = 19^6 mod 23 = 47045881 mod 23 = 2 server: A^b mod p = 8^15 mod 23 = 35184372088832 mod 23 = 2 BOTH GET 2 -> the shared secret is 2, and it was NEVER sent. QUICK CHECK with command-line bc (optional): echo "5^6 % 23" | bc -> 8 echo "5^15 % 23" | bc -> 19 echo "19^6 % 23" | bc -> 2 echo "8^15 % 23" | bc -> 2 WHAT THE EAVESDROPPER KNOWS vs DOESN'T: KNOWS: p=23, g=5, A=8, B=19 (everything transmitted) DOESN'T KNOW: a=6, b=15, and the shared secret 2 To find the secret, the eavesdropper must solve g^a mod p = A for a (i.e. 5^a mod 23 = 8) — the DISCRETE LOGARITHM problem. With p=23 you could brute-force it, but with the ~2048-bit primes (or 256-bit elliptic curves) used in real TLS, it is computationally infeasible. THAT is the "un-mixing the paint is hard" property made concrete. MAPPING TO THE PAINT ANALOGY: p, g = the shared base colour (yellow) a, b = each side's secret colour (red, blue) A, B = the mixed colours they send (orange, green) shared secret = the final brown both arrive at, never transmitted