Diffie-Hellman Key Exchange - Problem
Implement the Diffie-Hellman Key Exchange algorithm to simulate secure key exchange between two parties (Alice and Bob). This cryptographic protocol allows two parties to establish a shared secret key over an insecure communication channel without prior knowledge of each other.
Given a prime number p and a primitive root g, along with Alice's private key a and Bob's private key b, your task is to:
1. Calculate Alice's public key: A = g^a mod p
2. Calculate Bob's public key: B = g^b mod p
3. Calculate the shared secret from Alice's perspective: secret_alice = B^a mod p
4. Calculate the shared secret from Bob's perspective: secret_bob = A^b mod p
5. Return an object containing all intermediate values and verify that both parties arrive at the same shared secret.
The beauty of this algorithm is that even if an eavesdropper intercepts the public keys A and B, they cannot easily compute the shared secret without knowing the private keys a or b (assuming the discrete logarithm problem is hard).
Input & Output
Constraints
- 2 ≤ p ≤ 106 (p is prime)
- 1 ≤ g < p (g is primitive root mod p)
- 1 ≤ a, b < p (private keys)
- All computations done modulo p