Aim :- Implement Diffie-Hellmen Key Exchange Method.
C Program Code :
#include<stdio.h>
#include<conio.h>
// Function to compute a^m mod n
int power(int a, int m, int n)
{
int r;
int y=1;
while(m>0)
{
r=m%2;
if(r==1)
{
y=(y*a)%n;
}
a=a*a%n;
m=m/2;
}
return y;
}
void main()
{
int q=23,al=5;
int xa,xb,ya,yb,ka,kb;
clrscr();
xa=6;
xb=15;
printf("Implement Diffie-Hellman Key Exchange Method.\n\n");
ya=power(al,xa,q);
yb=power(al,xb,q);
ka=power(yb,xa,q);
kb=power(ya,xb,q);
printf("q : %d\nalpha : %d\n",q,al);
printf("Xa : %d\nXb : %d\n",xa,xb);
printf("Ya : %d\nYb : %d\n",ya,yb);
printf("Ka : %d\nKb : %d",ka,kb);
getch();
}
Output :
0 Comments