利用异或的性质来对文件进行加密:
复制代码 代码如下:
c=a^b
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);
}
时间: 2024-10-24 01:31:41