Remark11.4.1
Sage note:
Remember, this cell contains the commands used to make numbers from letters, so always evaluate it before doing any en/decoding.
Remember, we begin by doing this cell, which enables us to turn words into numbers. But really, what we care about are the numbers, because there are lots of other ways to turn words into numbers. So just use this if you want a quick number for a message.
Sage note:
Remember, this cell contains the commands used to make numbers from letters, so always evaluate it before doing any en/decoding.
There is a quite useful application of D-H called key exchange. Here is the basic concept.
Two people trying to pass information (universally called Alice and Bob) want to decide on a secret key for using some encryption routine. Unfortunately, they know that someone may be listening in on their decision. Instead of trying to send a secret key one has chosen, they try to create a secret key using (essentially) public means. Here's how it works.
Alice and Bob pick \(p=991\) and \(g=55\), and then (separately) pick \(m=130\) and \(n=123\). Then they compute the powers.
Okay, now what Alice and Bob do with this (possibly spied upon) information of \(g^n\) and \(g^m\) and \(g\) and \(p\) is to exponentiate the other person's number with their own power. Like this:
Note the code takes one power to the m and the other power to the n.
Thus, now they have a secret key (\(g^{mn}=g^{nm}\)) they can easily compute but which a spy in the middle cannot. Feel free to try this with your own numbers you pick!
This gives an encryption key useful to both Alice and Bob, to protect from any potential Eve who might be listening in. (That's Eve for eavesdropping, believe it or not – also a universal person in these stories.)
On the down side, if Eve not only is listening, but actually has access to Alice and Bob's transmissions and can change them, she can actually add her own exponent \(\ell\) to the game, so that she pretends to have secret key \(g^{m\ell}\) with Alice and secret key \(g^{n\ell}\) with Bob. Both of their keys' security is now compromised. Such a situation is known as a "Man in the Middle" attack. There is no obvious way to stop this if Eve has that much power.