Step 1: Public Information Setup

Public information is shared openly between Alice and Bob. This includes a large prime number (p) and a generator (g). An eavesdropper can see these values, but they alone don't reveal the final shared secret.
Selects a large prime number for the key exchange
Chooses a primitive root modulo p
Important: Both Alice and Bob can see the same public values (p, g). These are not secret and can be transmitted over an insecure channel.

Step 2: Private Key Generation and Public Key Calculation

Each participant generates their own private key (secret) and calculates their public key using the formula: Public Key = g^(private key) mod p

Alice

Alice's secret private key (kept secret)
Alice's public key (can be shared openly)
Bob's public key (g^b mod p)
Final shared secret: (g^b)^a mod p = g^(ab) mod p

Bob

Bob's secret private key (kept secret)
Bob's public key (can be shared openly)
Alice's public key (g^a mod p)
Final shared secret: (g^a)^b mod p = g^(ab) mod p

Step 3: Verification

Success! If both Alice and Bob calculated the same shared secret value, they have successfully established a secure communication channel. This shared secret can now be used as an encryption key for further communication.
Security Note: Even though an eavesdropper can see all the public information (p, g, g^a mod p, g^b mod p), they cannot easily compute the shared secret g^(ab) mod p without solving the discrete logarithm problem, which is computationally difficult for large numbers.