PRACTICAL NO:6
        DIFFIE-HELLMAN KEY EXCHANGE ALGORITHM
Diffie-Hellman is a mathematical problem that is the foundation for many cryptographic protocols. Diffie-Hellman is one of the greatest inventions in Cybersecurity. This revolutionary algorithm was proposed by Whitfield Diffie and Martin Hellman in 1976, enabling two entities to agree upon a secret key without prior arrangements, even in the presence of potential eavesdroppers. Diffie-Hellman offers a powerful solution to secure key exchange which has always been challenging and prone to alteration, thus ensuring confidentiality and integrity in information. 
CODE:
import random
def power(base,exponent,mod):
    result=1
    base=base%mod
    while exponent > 0:
        if exponent % 2 == 1:
            result=(result*base)%mod
        exponent=exponent >> 1
        base=(base*base) % mod
    return result
p=19
g=5
a_private=random.randint(1,p-2)
a_public=power(g,a_private,p)
b_private=random.randint(1,p-2)
b_public=power(g,b_private,p)
a_shared_key=power(b_public,a_private,p)
b_shared_key=power(a_public,b_private,p)
print("Public parameters:")
print(f"Prime (p): {p}")
print(f"Primitive root (g)|: {g} \n")
print("Alice's private key:",a_private)
print("Alice's public key:",a_public)
print("Bob's private key:",b_private)
print("Bob's public key:",b_public)
print("\nShared key computed by Alice:",a_shared_key)
print("Shared key computed by Bob:",b_shared_key)
if a_shared_key == b_shared_key:
    print("\nKey exchange successful!! Shared symmetric key established. ")
else:
    print("\nKey exchange failed. ")
OUTPUT:
