i have written the following code using codeblcoks.... for
diffie hellman asymmetric key encryption system
my code doesnt show any syntax errors but i am not able to decrypt my encrypted msg as i am outputs which are partly correct and partly incorrect.
int main()
{int randnum;
unsigned int seedval;
time_t t;
seedval=(unsigned)time(&t);
srand(seedval);
//test code
/*cout<<cal(123, 456, 567)<<"\n";
int j,k;
for(int i=0;i<40;i++)
cout<<rndpu(j)<<" "<<rndpu(k)<<"\n";
*/
int publicx[10]={2,3,5,7,11,13,17,19,23,29};
int publicy[10]={31,37,41,43,47,51,53,57,61,67};
int privatekey[20]={2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21};
int x,y,pra,prb,exa,exb,resulta,resultb,q;
int ra[600],rb[600],z;
//z decides size of msg
for(z=0;z<=600;z++)
{x=publicx[rndpu(q)];
y=publicy[rndpu(q)];
pra=privatekey[rndpr(q)];
prb=privatekey[rndpr(q)];
cout<<"z "<<z<<" "<<"x "<<x<<" "<<"y "<<y<<" "<<"pra "<<pra<<" "<<"prb "<<prb;
exa=cal(x, pra, y);
exb=cal(x, prb, y);
cout<<" "<<"exa "<<exa<<" "<<"exb "<<exb;
resulta=cal(exb, pra, y);
resultb=cal(exa, prb, y);
cout<<" "<<"resulta "<<resulta<<" "<<"resultb "<<resultb<<"\n";
ra[z]=resulta;
rb[z]=resultb;
}
cout<<"-----------------------------------------------------------------";
cout<<endl;
char msg[600],msge[600],msgd[600];
cout<<"enter msg: ";
gets(msg);
cout<<"\nyour entered msg is: "<<msg;
int length,l;
l=length;
length=strlen(msg);
cout<<"\n\n"<<"msg entered by A is: "<<msg;
encrypt(msg, msge, ra);
cout<<"\n\n"<<"encrypted msg sent by A is: "<<msge;
cout<<"\n\n"<<"encrypted msg received by B is: "<<msge;
decrypt(msge, msgd, rb);
cout<<"\n\n"<<"msg decrypted by B is: "<<msgd;