时间:2021-07-07 08:50:57 | 栏目:C代码 | 点击:次
利用异或的性质来对文件进行加密:
c^b=a
#include "stdio.h"
#include "stdlib.h"
void main(int argc,char *argv[])
{
FILE *fp1,*fp2;
char c,ch;
long j;
if(3!=argc)
{
printf("Command error/n");
exit(1);
}
if((fp1=fopen(argv[1],"rb"))==NULL)
{
printf("Can not open the source file/n");
exit(1);
}
if(NULL==(fp2=fopen(argv[2],"wb")))
{
printf("Can not open the aim file/n");
exit(1);
}
printf("Please input the password:/n");
scanf("%i",&j);
srand(j);
ch=fgetc(fp1);
while(!feof(fp1))
{
c=rand();
ch=ch^c;
fputc(ch,fp2);
ch=fgetc(fp1);
}
fclose(fp1);
fclose(fp2);
}