28. 使用fgetc()/fputc()实现文件的加密与解密,存在溢出风险。

 1 //使用fgetc()/fputc()实现文件的加密与解密,存在溢出风险。
 2 #include <stdio.h>
 3 #define F_PRINT_ERR(e)\
 4 do\
 5 {\
 6     if(e == NULL)\
 7     {\
 8       printf("open error");\
 9       exit(-1);\
10     }\
11 }\
12 while(0)
13 
14 #define CODE 10
15 
16 //加密,生成新的加密文件。
17 #if 1
18 int main(void)
19 { 
20     FILE* pfSrc = fopen("G:/qtcode/pfr.txt","r+");
21     F_PRINT_ERR(pfSrc);
22 
23 
24     FILE* pfDes = fopen("G:/qtcode/pfrcode.txt","w+");
25     F_PRINT_ERR(pfDes);
26 
27     char ch;
28 
29     while((ch = fgetc(pfSrc)) != EOF)
30     {
31         fputc(ch+CODE,pfDes);
32     }
33     fclose(pfSrc);
34     fclose(pfDes);
35     return 0;
36 }
37 #endif
38 
39 
40 //解密,生成新的解密文件。
41 #if 0
42 int main(void)
43 {
44     FILE* pfSrc = fopen("G:/qtcode/pfrcode.txt","r+");
45     F_PRINT_ERR(pfSrc);
46 
47 
48     FILE* pfDes = fopen("G:/qtcode/pfrdecode.txt","w+");
49     F_PRINT_ERR(pfDes);
50 
51     char ch;
52 
53     while((ch = fgetc(pfSrc)) != EOF)
54     {
55         fputc(ch-CODE,pfDes);
56     }
57     fclose(pfSrc);
58     fclose(pfDes);
59     return 0;
60 }
61 #endif

 

转载于:https://www.cnblogs.com/ZhuLuoJiGongYuan/p/9475477.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值