In my previous article/video how does encryption work? I wrote about the principles of encryption starting with the Caesar cipher and following the development of cryptography through to the modern day with systems like DES and AES. All these systems of encryption have one thing in common, you need to use a key to encrypt and decrypt the message.
Gary also Explains:
All encryption systems are rendered useless if a third party can discover the key used to encrypt the data. Therefore how keys are passed from one party to another, how keys are distributed is very important. If two people are friends then the issue of key distribution is simple, you meet up in private and swap key information. However if one person is in Europe and the other in North America, how do they exchange the keys without the possibility of a third person eavesdropping? This problem is magnified many times over when we consider the nature of the Internet. All our shopping on Amazon, eBay or wherever is based on the idea that our transactions are protected by encryption. But how does my web browser know what key to use when chatting to Amazon’s servers?
Fortunately the problem of key distribution was cracked nearly 40 years ago in the form of the Diffie–Hellman–Merkle key exchange and then shortly afterwards with the advent of public key cryptography.
Diffie–Hellman–Merkle key exchange
If Alice and Bob want to communicate securely but they are worried about Eve spying on them, how can Alice and Bob agree on a key for use with a symmetric cipher like DES without Eve finding out the key? That was the question that preoccupied Martin Hellman along with his colleagues Whitfield Diffie and Ralph Merkle during the mid 1970s. After a couple years of head scratching Martin Hellman had a revelation based on the idea of one-way functions. It works like this:
Alice picks a number and so does Bob. Alice picks 10 and Bob picks 2. They have both previously agreed to use the one-way function Y^X (mod P) where Y is 7 and P is 13, it can be a publicly agreed formula. So Alice plugs her number into the formula and gets: 7^10 (mod 13) = 4. Bob does the same and gets 7^2 (mod 13) = 10.