提供的头文件定义缓冲限制1M,文件大小超过1M的要注意。
简单写个,未测试。
#include <stdio.h>
#include <stdlib.h>
void _EncDecFile(char *OutFileName, char *InFileName, char *key, int Flags)
{
FILE *in, *out;
if ((in=fopen(InFileName, "rb")) == NULL)
exit(0);
if ((out=fopen(OutFileName, "wb")) == NULL)
exit(0);
char ch;
char *p=key;
while ((ch=fgetc(in)) != EOF)
{
if (Flags)
fputc(ch + *p, out);
else
fputc(ch - *p, out);
++p;
if (*p == 0)
p = key;
}
fclose(in);
fclose(out);
}
int main()
{
char *key = "20160505310024";
_EncDecFile("EncrytFile.txt", "OriginalFile.txt", key, 1);
_EncDecFile("DecrytFile.txt", "EncrytFile.txt", key, 0);
return 0;
}