#code :
from math import gcd, pow

p, g = map(int, input("Enter public key tuple (p g)  ").split())

a = int(input("Enter private key for user 1  "))
b = int(input("Enter private key for user 2  "))

x = pow(g,a)%p
y = pow(g,b)%p

# print("Generated key for user 1 is {} and user 2 is {}".format(x,y))
# print('\n\n')

print("Key received by user1 ====>",y)
print("Generating shared secret key using {}....".format(y))
print('.\n.\n.')
ka = pow(y,a)%p
print("Shared secret generated by user1 is ",ka)
print('\n\n')
print("Key received by user2 ====>",x)
print("Generating shared secret key using {}....".format(x))
print('.\n.\n.')
kb = pow(x,b)%p
print("Shared secret generated by user2 is",kb)


if ka==kb :
    print("\nSuccess 200.\n Secret key is",kb)
else:
    print("\nSomething went wrong. :(")

"""
Output:

Enter public key tuple (p g)  23 9
Enter private key for user 1  3
Enter private key for user 2  4
Key received by user1 ====> 6.0
Generating shared secret key using 6.0....
.
.
.
Shared secret generated by user1 is  9.0



Key received by user2 ====> 16.0
Generating shared secret key using 16.0....
.
.
.
Shared secret generated by user2 is 9.0

Success 200.
Secret key is 9.0
"""