Worksheet 2.1
Worksheet 2.1
: 5
2. Algorithm/Flowchart:
The Diffie–Hellman (DH) Algorithm is a key-exchange protocol that enables two parties
communicating over public channel to establish a mutual secret without it being transmitted
over the Internet. DH enables the two to use a public key to encrypt and decrypt their
conversation or data using symmetric cryptography.
1. The first party picks two prime numbers, g and p and tells them to the second party.
2. The second party then picks a secret number (let’s call it a), and then it computes ga mod p
and sends the result back to the first party; let’s call the result A. Keep in mind that the secret
number is not sent to anyone, only the result is.
3. Then the first party does the same; it selects a secret number b and calculates the result B
similor to the step 2.
4. Then, this result is sent to the second party.
5. The second party takes the received number B and calculates B(a) mod p.
6. The first party takes the received number A and calculates A(b) mod p.
The answer in step 5 will be the same as the answer in step 4. This means both parties will get
the same answer no matter the order of exponentiation.
3. Code:
#include<iostream>
using namespace std;
class DiffieHellman
{
public:
long long int p,g,x,a,y,b,A,B;
DiffieHellman(long long int p1,long long int g1,long long int
x1,long long int y1)
{
p = p1;
g = g1;
x = x1;
y = y1;
a=power(g,x,p);
b=power(g,y,p);
A = power(b,x,p);
B = power(a,y,p);
}
int main()
{
long long int p,g,x,a,y,b,A,B;
cout<<"Enter the values of p and g upon which both parties will aggree :
"<<endl;
cin>>p>>g;
Code Snippet:
4. Output:
Learning outcomes:
3. Learnt the uses and advantages of Diffie Hellman Key Exchange Algorithm.