文件加密与解密
#include <stdio.h> #include <string.h>
#include<stdlib.h>
char encrypt(char f, char c)
{ return f ^ c; }
void main()
{ FILE *fp, *fp1;
char fn[40], *p=fn, ps[10], *s=ps;
char ch;
char *tm= "序列号.txt";
printf("Input the path and filename:");
gets(p);
*tm=*p;
if((fp=fopen(p, "rb"))==NULL || (fp1=fopen(tm, "wb"))==NULL)
{ printf("Cannot open file strike any key exit!");
getchar();
exit(0);
}
printf("Input the password:");
gets(s);
ch=fgetc(fp);
while(!feof(fp))
{ s=ps;
while(*s!= '\0')
ch=encrypt(ch, *s++);
fputc(ch, fp1);
ch=fgetc(fp);
}
fclose(fp); fclose(fp1);
remove(p);
rename(tm, p);
}
这是这个程序的源代码,但是运行不了,希望高手帮帮忙啊!