int
encryption(
char
*in_fname,
char
*pwd,
char
*out_fname)
{
FILE
*fp_1, *fp_2;
register
char
ch;
int
i = 0, pwd_length = 0;
fp_1 =
fopen
(in_fname,
"rb"
);
if
(fp_1 == NULL) {
fprintf
(stderr,
"cannot open in-file: %s.\n"
, in_fname);
return
-1;
}
fp_2 =
fopen
(out_fname,
"wb"
);
if
(fp_2 == NULL) {
fprintf
(stderr,
"cannot open out-file: %s.\n"
, out_fname);
return
-1;
}
pwd_length =
strlen
(pwd);
while
( (ch =
fgetc
(fp_1)) != EOF)
fputc
(ch ^ pwd[i > pwd_length ? i = 0 : i++], fp_2);
fclose
(fp_1);
fclose
(fp_2);
return
0;
}
转载自:http://www.oschina.net/code/snippet_242134_16757