Recall the mathematics of Diffie-Hellman: Given public. Stack Exchange Network. Stack Exchange network consists of 176 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers. The Elliptic-Curve Diffie–Hellman (ECDH) is an anonymous key agreement protocol that allows two parties, each having an elliptic-curve public–private key pair, to establish a shared secret over an insecure channel. Dirty Diffie-Hellman (Like dirty Santa, but geekier) Crappy PHP script for a simple Diffie-Hellman key exchange calculator. I guess I could have used Javascript instead of PHP, but I. Diffie Hellman Algorithm (DH) Diffie Hellman (DH) key exchange algorithm is a method for securely exchanging cryptographic keys over a public communications channel. Keys are not actually exchanged – they are jointly derived. It is named after their inventors Whitfield Diffie and Martin Hellman. The Diffie-Hellman key exchange uses a large prime pand a primitive root gof this prime. These numbers are both public. To start the key exchange process, Alice chooses a secret number aless than the large prime, and computes ga(mod p). Alice sends this answer, call it A, to Bob.
You already use modulo computation when you look at the clock and e.g. needs to figure out what time it's 3 hours after 11 o'clock, which is 2 o'clock. In math we write that as:
( (11 + 3) : mod : 12 = 2 )
where 12 is the modulus because we want the time as an integer between 0 and 11 (12 o'clock is in this case denoted by 0). In words we say 11 plus 3 modulo 12 is equal 2. The result of a modulo computation is an integer between 0 and the modulus minus 1. E.g. with the modulus 3 we have that:
If we e.g. look at ( 27 : mod : 5 ) then modulo computes the number of times 5 divides 27 and then returns the remainder of the result which is 2 in this case, i.e. ( 27 : mod : 5 = 2 ). But how did we get this result?
First we compute the number of times it's possible to multiply 5 with the number ( x ) such that we get an integer as close as possible to 27 without exceeding it, i.e. we have to find the maximun value of ( x ) such that ( 5 cdot x leq 27 ). In this case we have that ( x = 5 ) because ( 5 cdot 5 = 25 leq 27 ). Then by subtracting 27 with 25 we get the answer ( 27 - 25 = 2).
If the integer is negative e.g. ( -27 : mod : 5 ) we have to do it slightly different and the answer is ( -27 : mod : 5 = 3 ). In this case the integer ( x ) is negative and should be the closest integer that exceed -27, i.e. we have to find the minimum value of ( -x ) such that ( 5 cdot -x geq -27 ). Now we have that ( -x = -6 ) because ( 5 cdot -6 = -30 geq -27 ). Then by subtracting -27 with -30 we get the answer ( -27 - (-30) = -27 + 30 = 3).
It's important that ( x ) or ( -x ) is an integer such as ( -14, 3, 17 ) etc. and NOT a fraction or float such as ( frac{1}{4}, frac{-3}{7}, 2.5, 5.1 ) etc.
If two integers ( a ) and ( b ) modulo the same modulus ( c ) returns the same remainder ( r ), then we say that ( a ) and ( b ) are congruent modulo ( c ). I.e. if ( a : mod : c = r ) and ( b : mod : c = r ) then ( a equiv b : (mod : c) ). Also, notice that if the modulus ( c ) is greater than the integer ( a ), i.e. ( c > a ), the result will always be equal ( a : mod : c = a ).
HomeTake on the roles of Alice and Bob! Exchange secret keys using the Diffie-Hellman key exchange method!! Use your keys to encrypt messages!!!
The Diffie-Hellman key exchange uses a large prime p and a primitive root g of this prime. These numbers are both public.
To start the key exchange process, Alice chooses a secret number a less than the large prime, and computes ga (mod p). Alice sends this answer, call it A, to Bob. Bob now chooses his own secret number b, and computes gb (mod p). Bob sends this answer, call it B, to Alice.
Finally, Alice computes Ba (mod p), and Bob computes Ab (mod p). They both get the same answer, but no-one else will know this secret answer, because only Alice knows a, and only Bob knows b. This secret answer is their private key, which they can use to encrypt messages.
[You may wonder why someone intercepting Alice and Bob's communication can't solve gx = A (mod p) to calculate Alice's secret number a. This is a hard problem, known as the discrete logarithm problem. That this is difficult is the strength of this method of key exchange.]
First you must be Alice. Choose a large prime from the list below (or one of your own choice) and a corresponding primitive root of that large prime. Then choose a secret number which is smaller than your large prime.