|
[code:1]
#include "iostream.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
void PressExit(){cout<<"Press any key to exit.";getch();}
char XORCHRW(char c,char *key)
{
char ret=c;
int i;
for(i=0;i<strlen(key);i++)
(ret=c)^=*(key+i);
return ret;
}
char XORCHRL(char c,char key[])
{
int i;
int ret=c;
for(i=0;i<strlen(key);i++) ret^=key[i];
return ret;
}
int main()
{
char fn[255];
FILE *ifp, *ofp;
cout<<"Please input source file name which is TO BE ENCRYPTED:"<<endl;
cin>>fn;
if((ifp=fopen(fn,"rb"))==NULL)
{
//An error occured while opening file, exit.
cerr<<"Cannot open file!"<<endl;
PressExit();
return 0;
}
else
{
//Input file names and key.
cout<<"Please input destination file name:"<<endl;
cin>>fn;
char key[256];
cout<<"Please input key: ";
cin>>key;
ofp=fopen(fn,"wb");
char buf=fgetc(ifp);
while(buf!=EOF)
{
fputc(XORCHRW(buf,key),ofp);
buf=fgetc(ifp);
}
fclose(ofp);
fclose(ifp);
return 1;
}
}
[/code:1]
(ret=c)^=*(key+i);
哪位帮我解释一下这句?
这个程序是用来用异或加密文件的。
自已做出来了,但是好像和原来想的不一样。
应该就是这句出的问题。 |
|