Diffie-Hellman ExampleDiffie-Hellman is a standard method of Alice and Bob being able to communicate, and end up with the same secret encryption key. It is used in many applications. [Lecture] [Tutorial] [Theory]
Next Bob and Alice will generate two random numbers (X and Y), calculate an X value and a Y value, respectively:
and Bob will send his A value to Alice, and Alice will send her B value to Bob, and they now re-calculate the values to generate the same shared key:
PresentationCodeOutline of code used[HttpPost] public ActionResult diffie2(hashing h, string button1) { int x = Global.random(90); int y = Global.random(90); BigInteger g = new BigInteger("153d5d6172adb43045b68ae8e1de1070...cb9a428cc", 16); BigInteger n = new BigInteger("9494fec095f3b85ee286542b3836fc81...ca98cdf3b", 16); BigInteger A = g.Pow(x).Mod(n); BigInteger B = g.Pow(y).Mod(n); ViewData["GValue"] = g.ToString(); ViewData["Nvalue"] = n.ToString(); ViewData["XValue"] = Convert.ToString(x); ViewData["Yvalue"] = Convert.ToString(y); BigInteger k1=B.Pow(x).Mod(n); BigInteger k2=A.Pow(y).Mod(n); ViewData["Avalue"] = A.ToString(); ViewData["Bvalue"] = B.ToString(); ViewData["BobKey"] = k1.ToString(); ViewData["AliceKey"] = k2.ToString(); if (k1 == k2) h.message = "Success ... the keys match!!!"; else h.message = "Failed ... probably due to math overload"; return PartialView("diffie2partial"); }
|