DiffieHellman key agreement
Principles
DiffieHellman key agreement allows two principals (people) to agree upon a shared key without authentication.
Algorithm
Setup
We have a public, large, secure prime
Key Exchange
The following calculations all take place
 We have principals
$A$ and$B$  The principals choose keys

$A$ selects a random integer$x$ such that$1 \leq x \lt p1$ 
$B$ selects$y$ similarly

 The principals send their keys

$A \overset{g^x}{\rightarrow} B$ 
$B \overset{g^y}{\rightarrow} A$

 The principals calculate the same key together

$A$ receives$m =g^y$ from$B$ and calculates$m^x = (g^y)^x = g^{xy}$ 
$B$ receives$n = g^x$ and calculates$g^{xy}$ similarly

 Both principals now know
$g^{xy}$ in such a way that a passive attacker cannot find it, presuming DHP to be intractable.
Attacking
DiffieHellman is vulnerable to a man in the middle attack in which
an eavesdropper