# Function to perform the Diffie-Hellman key exchange def diffie_hellman(P, G, a, b): # Calculate public keys A = (G ** a) % P B = (G ** b) % P # Calculate shared secret S1 = (B ** a) % P S2 = (A ** b) % P # Ensure shared secrets match assert S1 == S2, "Shared secrets do not match!" return S1 # Parameters P = 33 G = 8 a = 3 # User 1's private key b = 2 # User 2's private key # Perform Diffie-Hellman key exchange shared_secret = diffie_hellman(P, G, a, b) # Function to decode hash using shared secret def decode_hash(hash_value, shared_secret): decoded_hash = int(hash_value, 16) ^ shared_secret # Convert hash to integer and perform XOR return decoded_hash # Provided hash value hash_value = "cd7760167c59fa13ddc180e7ce78c5e7e23eb54dc2e38bd2a0022058b16a5de98b2d579e680a4caa3b8b507dba9c1944" # Decode hash using shared secret decoded_hash = decode_hash(hash_value, shared_secret) print("Shared Secret:", shared_secret) print("Decoded Hash:", hex(decoded_hash)[2:]) # Convert decoded hash back to hexadecimal and remove the '0x' prefix