Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Project: 1 One of the main challenge to use a security key algorithm such as RC4

ID: 3919279 • Letter: P

Question

Project: 1 One of the main challenge to use a security key algorithm such as RC4 is the key exchange. Very often the key exchange must be done offline, otherwise you run the risk of the key being eavesdropped by a hacker. Now implement Diffie-Hellman Key Exchange Algorithm in Ctt.A user will be asked to enter two prime numbers g and p, in the range 4000 to 10000. Then user A enters a number a, and user B enters a number b, both in the range of 40 to 100. Now compute the security keys generated by user A and user B respectively, and verify they are the same. Be aware that if you use the powl) function or something similar, your calculation will most likely go out of bounds. As any good program would do, your program should verify the inputs. 1. Source code (please give Ans in C++) 2. A screen shot showing the keys generated by A and B.

Explanation / Answer

#include<iostream>

#include<cstdio>

#include<math.h>

using namespace std;

class DiHellman

{

       public:

              long long int p,g,x,a,y,b,A,B;

              DiHellman(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);

              }

              long long int power(int a,int b,int mod)

              {

                     long long int t;

                     if(b==1)

                           return a;

                     t=power(a,b/2,mod);

                     if(b%2==0)

                           return (t*t)%mod;

                     else

                           return (((t*t)%mod)*a)%mod;

              }

};

int main()

{

       long long int p,g,x,a,y,b,A,B;

      

       cout<<"Enter the values of p and g : "<<endl;

       cin>>p>>g;

      

       cout<<"Enter the number for A : ";

       cin>>x;

       cout<<"Enter the number for B : ";

       cin>>y;

       cout<<endl;

       int j = DiHellman dh(p,g,x,y);

      

       cout<<"A private key : "<<dh.a<<endl;

       cout<<"B private key : "<<dh.b<<endl;

       cout<<endl;

       if(dh.a == dh.b){

               cout<<"The keys are same";

       }

       else

               cout<<"The keys are not same";

       return 0;

}