用位异或加密文件
这是一个用位异或加密文件的程序。能不能帮我仔细看一下,感激不尽,小弟我想这个问题好久了#include<stdio.h>
void jiami(char*infile,char*password,char*outfile)
{
char c,*cc=&c;int i,j=strlen(password);
FILE*fp1,*fp2;
if((fp1=fopen(infile,"rb"))==0)
{
printf("cannot open infile\n");
getch();
exit(0);
}
if((fp2=fopen(outfile,"wb"))==0)
{
printf("cannot open outfile\n");
getch();
exit(0);
}
i=0;
while(!feof(fp1))
{
fread(cc,sizeof(char),1,fp1);
fputc(c^password[i++],fp2);
if(i==j)
i=0;
}
fclose(fp1);
fclose(fp2);
}
main()
{
FILE*fp;
char a[20],b;
int i,j,k=0;
char c,*cc=&c;
char infile[20];
char outfile[20];
char password[10];
printf("choose\n");
printf("1.jiami\n");
printf("2.jiemi\n");
b=getchar();
getchar();
if(b=='1')
{
printf("input in file\n");
do
{
scanf("%s",infile);
if(strlen(infile)>19)
printf("too long\n");
}while(strlen(infile)>19);
printf("outfile\n");
do {
scanf("%s",outfile);
if(strlen(outfile)>19)
printf("too long\n");
}while(strlen(outfile)>19);
printf("input password\n");
do
{
scanf("%s",password);
if(strlen(password)>10)
printf("too long\n");
}while(strlen(password)>10);
jiami(infile,password,outfile);
printf("successful\n");
getch();
}
else
{
printf("infile\n");
scanf("%s",a);
fp=fopen(a,"rt");
if(fp==0)
{
printf("error\n");
getch();
exit(0);
}
printf("password\n");
do
{
scanf("%s",password);
if(strlen(password)>10)
printf("too long\n");
}while(strlen(password)>10);
j=strlen(password);
i=0;
while(!feof(fp))
{
fread(cc,sizeof(char),1,fp);
outfile[k++]=c^password[i++];
if(i==j)
i=0;
}
outfile[k]='\0';
printf("%s",outfile);
getch();
}
}
以上编译能通过,但是打开加密文件对它解密却多显示出二个字符,哪里错了,哪位大哥帮我运行一下除下错