Mutual authentication using public key cryptography
#include<conio.h>
#include<stdio.h>
struct KDC
{
int k1;
int k2;
}KDC;
struct A
{
int k;
int x;
int key;
int key1;
int key2;
int key3;
int y;
int a;
}A;
struct B
{
int k;
int key;
int key1;
int key2;
int key3;
int x;
int y;
int a;
}B;
void main()
{
int i;
int ch;
clrscr();
A.k=k();
B.k=k();
KDC.k1=A.k;
KDC.k2=B.k;
printf("\n want to start the communication press(1.yes / 2.no) ");
scanf("%d",&ch);
if(ch==1)
{
printf("\n request for private key :: ");
delay(100);
printf("\n key provided ");
A.x=B.k;
A.a=random();
A.key=A.x + A.a;
//msg3
B.key=A.key;
B.x=B.key-B.k;//decrypt number
printf("\n request for key");
delay(500);
printf("\n key provided ");
sound(100);
delay(500);
nosound();
B.y=A.k;
B.a=random();
B.key1=B.y + A.a;//my challenge
B.key2= B.x+A.a; //response
B.x=random();
B.key3=B.x+A.a; //session key
//reply
//msg6
A.key1=B.key2;// - A.a;//response
A.key2=B.key1;// - A.a;//challenge
A.key3=B.key3;//-A.a;//session key
A.key1=A.key1-A.a;
if(A.key1==A.a)
{
printf("\n Receiver is verified.");
printf("\n further communication..........");
delay(500);
}
else
{
printf("\n verification fail !!!");
goto exit;
}
//A generate the response
A.y=A.key2-A.a;
B.y=A.y+B.a;
//verification
B.y=B.y-B.a;
printf("\n Bob is authenticated !!!");
sound(100);
delay(500);
nosound();
}
else
{
printf("\ncommunication could not take place");
}
exit:
getch();
}
int k()
{
int a;
printf("\n enter the private key :: ");
scanf("%d",&a);
return (a);
}
int random()
{
int a;
a=rand()%10;
return (a);
}
OUTPUT:
enter the private key :: 5
enter the private key :: 3
want to start the communication press(1.yes / 2.no) 1
request for private key ::
key provided
request for key
key provided
Receiver is verified.
further communication..........
Bob is authenticated !!!