HERE IS SIMPLE XOR PROGRAM
WHEN I TRY TO COMPARE TWO SAME STRINGS ENCRYPTED WITH SAME KEY THEN IT SAYS COMPARISON IS WRONG
HERE IS CODE
#include<conio.h>
#include<iostream.h>
#include<windows.h>
#include<string.h>
using namespace std;
int main()
{
char st[100];
char key[100];
cout<<"ENter string ::";
cin>>st;
cout<<"\n";
cout<<"Enter key::";
cin>>key;
cout<<"\n";
int i;
int j;
int kk=strlen(st);
for(i=0,j=0;i<=kk;i++)
{
st[i]=st[i]^key[j++];
if(j==strlen(key))
{
j=0;
}
}
cout<<"ENCRYPTED TEXT::"<<st<<"\n";
char cm[100];
cout<<"Enter for compare::";
cin>>cm;
cout<<"\n";
int k1=strlen(cm);
for(i=0,j=0;i<=k1;i++)
{
cm[i]=cm[i]^key[j++];
if(j==strlen(key))
{
j=0;
}
}
cout<<cm;
if(strcmp(cm,st)==0)
{
cout<<"OK";
}
else
{
cout<<"\nWROMG\n";
}
getch();
return 0;
}
tell me where i am wrong