Alice and Bob want to encrypt their messages. They can't meet in person to exchange keys. They are constrained to use an open communication channel.

Diffie–Hellman key exchange

DH key exchange -- key exchange scheme as conceived by Ralph Merkle and published by Whitfield Diffie and Martin Hellman in 1976.

AliceBob
1
General algorithm parameters. These numbers can be unique or generally accepted.
M -- Large Safe Prime number (2048 bit) G (ground) -- Large number <M
2
Choose large numbers (random). Personal secrets. Large numbers <M
a -- secret key b -- secret key
3
Calculation of the public parts of the secret key P=Gkey (mod M). The public key is derived from the private key.
A = B =
4
Exchange of public parts of the future secret key.
5
The keys of the opposite parties to the correspondence.
B A
6
Calculating a shared encryption and decryption key
K=Ba=Ab=(Ga)b=(Gb)a=Ga×b (mod M)
K = K =

Comments

The Diffie-Hellman scheme is only useful for generating a shared secret key over an eavesdropped communication channel.

The message encryption algorithm is not related to the key exchange scheme.

The key exchange algorithm is not protected against Man-in-the-middle attacks.

Subskribita.net