0% found this document useful (0 votes)
55 views

Experiment No 3 Css

Experiment No 3 aims to implement the Diffie-Hellman algorithm using C. The code defines functions to calculate powers modulo a number and to calculate a key. It takes inputs for the public parameters n and g, and private inputs x and y. It then calculates and prints the shared keys for each person using the other's public parameter raised to their private exponent. The experiment concludes by stating it has shown how to implement Diffie-Hellman key exchange in C.

Uploaded by

116Tanzeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Experiment No 3 Css

Experiment No 3 aims to implement the Diffie-Hellman algorithm using C. The code defines functions to calculate powers modulo a number and to calculate a key. It takes inputs for the public parameters n and g, and private inputs x and y. It then calculates and prints the shared keys for each person using the other's public parameter raised to their private exponent. The experiment concludes by stating it has shown how to implement Diffie-Hellman key exchange in C.

Uploaded by

116Tanzeel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Experiment No :- 3

Aim :- To Implement Diffie-Hellman Algorithm Using C.


Roll No :- 32

Code :-
#include<stdio.h>
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;
}
long long int calculateKey(int a,int x,int n)
{
return power(a,x,n);
}
int main()
{
int n,g,x,a,y,b;
printf("Enter the value of n and g : ");
scanf("%d%d",&n,&g);
printf("Enter the value of x for the first person : ");
scanf("%d",&x);
a=power(g,x,n);
printf("Enter the value of y for the second person : ");
scanf("%d",&y);
b=power(g,y,n);
printf("key for the first person is : %lld\n",power(b,x,n));
printf("key for the second person is : %lld\n",power(a,y,n));
return 0;
}

Output :-

Conclusion :- In this experiment we have learned how to implement Diffie-Hellman


algorithm using C.

You might also like