# Diffie Hellman ## Problem Suppose I want to send a secure, encrypted message to another party over public channels. To do so, I need to establish and securely share a key with the other party. Now how do I do this when everything I share is public? That's what Diffie Hellman Key Exchange solves. ## Math 1. Start with a public generator g 2. Decide a public prime mod p 3. Both sides individually choose their own secret keys, a and b 4. Both sides raise the generator to their secret key under mod p (g^a^ mod p, g^b^ mod p) 5. Both sides share their newly computed value publicly as A and B 6. Both sides raise the other side's value (A or B) to their own secret key under mod p (A^b^ mod p, B^a^ mod p) 7. If everything worked, both sides now how the same number which they can use as a key for encryption ## Explanation This works because (g^a^)^b^ = g^ab^ (mod p) which is the same as (g^b^)^a^ = g^ba^ (mod p) Do note that Diffie Hellman cannot be used to send messages directly ## Discrete Log Problem Now why is it secure?