异或后 还原不回去 大家帮忙看看啊
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <math.h>
void descrypt_file()
{
int ch;
int key = 112;
int i = 0;
FILE * fp_dstTxt,*fp_srcTxt;
fp_dstTxt = fopen("dst.txt", "rb");
if(fp_dstTxt == NULL)
{
return;
}
fp_srcTxt = fopen("resource.txt","wb");
if(fp_srcTxt == NULL)
{
fclose(fp_dstTxt);
return;
}
int x = 0;
while( (ch=fgetc(fp_dstTxt)) != EOF )
{
x = (ch - i) ^ key;
fputc(x, fp_srcTxt);
key ^= ch;
i++;
}
fclose(fp_srcTxt);
fclose(fp_dstTxt);
}
void encrypt_file()
{
int ch,i = 0;
int key = 112;
FILE * fp_srcTxt,*fp_dstTxt;
fp_srcTxt = fopen("src.txt", "rb");
if(fp_srcTxt == NULL)
{
return;
}
fp_dstTxt = fopen("dst.txt","wb");
if(fp_dstTxt == NULL)
{
fclose(fp_srcTxt);
return;
}
int x = 0;
while( (ch=fgetc(fp_srcTxt)) != EOF )
{
x = (ch ^ key) + i;
fputc(x, fp_dstTxt);
key ^= ch;
i++;
}
fclose(fp_srcTxt);
fclose(fp_dstTxt);
}
int main(int argc, const char * argv[])
{
encrypt_file();
descrypt_file();
return 0;
}