zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    C++异常:exception
    C++关键字:explicit
    C++关键字:重学记录
    Unity jointmoto
    hashtable和hashmap
    Spring MVC 笔记 概述
    SQL上门2
    面试:A
    Java 初学者
    SQL上门
  • 原文地址:https://www.cnblogs.com/ZhuLuoJiGongYuan/p/9475477.html
Copyright © 2011-2022 走看看