Comment on page

# DHKE - Examples

Let's give a simple code example in Python to demonstrate the classical Diffie–Hellman Key Exchange (DHKE) algorithm.
First, install the Python package `PyDHE`:
pip install pyDHE
Next, write the code for the DHKE example:
import pyDHE
alice = pyDHE.new()
alicePubKey = alice.getPublicKey()
print("Alice public key:", hex(alicePubKey))
bob = pyDHE.new()
bobPubKey = bob.getPublicKey()
print("Bob public key:", hex(bobPubKey))
print("Now exchange the public keys (e.g. through Internet)")
aliceSharedKey = alice.update(bobPubKey)
print("Alice shared key:", hex(aliceSharedKey))
bobSharedKey = bob.update(alicePubKey)
print("Bob shared key:", hex(bobSharedKey))
print("Equal shared keys:", aliceSharedKey == bobSharedKey)
When you run the above code, it will generate and print two 2048-bit public keys (for Alice and for Bob). Assume that Allice and Bob have exchanged their public keys (e.g. send them to each other through Internet). Once Alice has received Bob's public key, she can calculate the shared secret by combining it to her private key. Respectively, once Bob has received Alice's public key, he can calculate the shared secret by combining it to his private key. The sample output from the above example shows that the shared secret is always the same number (2048-bit integer):
Now exchange the public keys (e.g. through Internet)