#include
#include
long double mod (long double q,long n)
{
long double rem=0, quo;
quo=q/n;
quo=floor(quo);
rem=q-(quo*n);
return rem;
}
int check_root(long int q,long int a)
{
long double arr[100];
int i,j,k=0,flag=1;
for(i=1;i {
arr[k]=mod(pow(a,i),q);
k++;
}
for(i=0;i
for(j=0;j
if ((i!=j) && (arr[i]==arr[j]))
{
flag=0;
break;
}
}
}
return flag;
}
void main()
{
clrscr();
long q,prem_root=2;
long p_A,k_A,p_B,k_B,pub_A,pub_B;
cout<<"Enter prime no : ";
cin>>q;
do
{
prem_root++;
}while(check_root(q,prem_root));
cout<<"Enter private key of A : ";
cin>>p_A;
pub_A=mod(pow(prem_root,p_A),q);
cout<<"Enter private key of B : ";
cin>>p_B;
pub_B=mod(pow(prem_root,p_B),q);
k_A=mod(pow(pub_B,p_A),q);
k_B=mod(pow(pub_A,p_B),q);
cout<<"Public key A : "<
{
cout<<"Key exchange successful...";
}
else
{
cout<<"Key exchange unsuccessful...";
}
getch();
}
No comments:
Post a Comment