这是一个简单的读取文件,异或后,再输出到另一文件中,起到一个简单的加密,
#include<stdlib.h>
#include<stdio.h>int main(int argc, const char *argv[])
{
FILE *fp,*pp;
char buf[123]="";
int i=0;
int j,k,l;
long long num=0;
char m[123]="";
char s[123]="";
printf("please input convert filename:");
scanf("%s",s);
getchar();
fp=fopen(s,"r");
pp=fopen("1.txt","w");
int n=1;
while(1){
n=fread(buf,1,1,fp);
if(n<=0)
break;
fprintf(pp,"%c",(buf[0]^0xff));//0xff 就是秘钥,也可以是任意的字母或者数字的组合
}
printf("convert %s is OK!\n",s);
printf("convert creat \"1.txt\" !");
exit(0);
return 0;
}
这是一个简单的读取文件,再一次异或同一个秘钥后,再输出到另一文件中,起到一个简单的解密,
#include<stdlib.h>
#include<stdio.h>
int main(int argc, const char *argv[])
{
FILE *fp,*pp;
char buf[123]="";
int i=0;
int j=0;
char m[123]="";
char s[123]="";
printf("please input convert file name:");
scanf("%s",s);
getchar();
fp=fopen(s,"r");
pp=fopen("1.txt","w");
int n=1;
while(1){
n=fread(buf,1,1,fp);
if(n<=0)
break;
buf[0]=buf[0]^0xff;//连续两次异或同一个秘钥,就可以起到解密的作用
fwrite(&buf[0],1,1,pp);
}
return 0;
}