0% found this document useful (0 votes)
31 views3 pages

#Include #Include Int Power (Int A, Int M, Int N) (

The document implements the Diffie-Hellman key exchange method to securely generate a shared secret key between two parties. It defines a power function to calculate exponentials modulo a prime number. The program then demonstrates the key exchange by having two parties, Alice and Bob, publicly exchange values derived from secret numbers to compute a common key.

Uploaded by

hgdrse
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)
31 views3 pages

#Include #Include Int Power (Int A, Int M, Int N) (

The document implements the Diffie-Hellman key exchange method to securely generate a shared secret key between two parties. It defines a power function to calculate exponentials modulo a prime number. The program then demonstrates the key exchange by having two parties, Alice and Bob, publicly exchange values derived from secret numbers to compute a common key.

Uploaded by

hgdrse
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/ 3

Practical: -7

AIM: -Implement Diffi-Hellmen Key exchange Method.

#include<stdio.h>

#include<conio.h>

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:-

You might also like