The Diffie-Hellman key exchange was a revolutionary application of integer arithmetic, to exchange encryption keys, in real-time, without pre-arrangment.
Since the mathematics is a little esoteric, it’s sometimes easier to employ the following illustration.
Bob and Alice have a wooden chest with a large hasp to lock it. Bob has a red combination lock. Alice has a green combination lock.
In the study, Bob writes the password on a small note, and locks it in the chest, with his red combination lock. He then asks or allows Eve, to transport the chest to Alice.
Alice cannot open Bob’s lock, but by request, she locks the hasp in a second way, using her own green combination lock. She then duly asks Eve to tote the chest back to Bob.
Bob in his turn unlocks his RED lock, and Eve makes one final trip, back to Alice with only one lock on the chest: Alice’s GREEN lock.
Since Alice knows the combination of her own lock, she is a liberty to request privacy from Eve, and in seclusion open the chest to reveal the newly agreed password.
When done in mathematics, the password is not decided by either party, but results from changes made during the process. Nonetheless, the exchange is analogous to the illustration above, and almost anyone can see that it is possible.
RSA public key encryption is analogous to Bob handing Alice his open, red lock. Alice never knows how to open it, and she cannot accept random red locks – she must ensure that it is Bob’s lock she receives.