I have written a simple program which encrypts text using XOR encryption.. I have put the source below...
The problem is the encryption and decryption works well for small strings some time.. But some time it does not work for anything.. Some time partial strings are decrypted and some time encryptiuon does not happen in full etc.. Please have a look...
The function exor take the input from the varaible e and also takes the password or key as the argument..... and encrypts data.
The function dxor takes the encrypted text and key or password as argements and decrypts the data
Code:
# include <iostream.h>
# include <conio.h>
# include <string.h>
char text[3600];
char xtext[3600];
char dtext[3600];
int exor(char text[],char pass[])
{
int l,p;
l=strlen(text);
p=strlen(pass);
int m=0;
for(int i=0;i<l;i++)
{
if(m>p-1)
m=0;
xtext[i]=text[i]^pass[m];
m=m+1;
}
return 0;
}
int dxor(char text[],char pass[])
{
int l,p;
l=strlen(text);
p=strlen(pass);
int m=0;
for(int i=0;i<l;i++)
{
if(m>p-1)
m=0;
dtext[i]=text[i]^pass[m];
m=m+1;
}
return 0;
}
int main()
{
clrscr();
char e[3600];
int t=0;
for(int i=0;i<3600;i++)
{
e[i]=getche();
t=t+1;
if(e[i]==13)
break;
}
t=t-1;
for(int y=t;y<3600;y++)
{
e[y]=( NULL );
}
cout<<"\n\n";
exor(e,"this is the passowrd key");
cout<<xtext<<"\n";
dxor(xtext,"this is the password key");
cout<<dtext;
return 0;
}
SOme one help please
Thanx