简单的C语言加密程序

01 int encryption(char *in_fname, char *pwd, char *out_fname)

02 {
03     FILE *fp_1, *fp_2;
04     register char ch;
05     int i = 0, pwd_length = 0;
06  
07     fp_1 = fopen(in_fname, "rb");
08  
09     if (fp_1 == NULL) {
10         fprintf(stderr, "cannot open in-file: %s.\n", in_fname);
11         return -1;
12     }
13  
14     fp_2 = fopen(out_fname, "wb");
15  
16     if (fp_2 == NULL) {
17         fprintf(stderr, "cannot open out-file: %s.\n", out_fname);
18         return -1;
19     }
20  
21     pwd_length = strlen(pwd);
22  
23     while ( (ch = fgetc(fp_1)) != EOF)
24         fputc(ch ^ pwd[i > pwd_length ? i = 0 : i++], fp_2);
25  
26     fclose(fp_1);
27     fclose(fp_2);
28  
29     return 0;
30 }

你可能感兴趣的:(简单的C语言加密程序)