zoukankan      html  css  js  c++  java
  • 文件操作(二进制文件加密解密)

    加密

    #include<stdio.h>
    #include<string.h>
    
    void code(char *p,size_t n)
    {
        size_t i;
        for(i = 0; i < n; i++)
        {
            p[i] += 3;
        }
    }
    
    int main()
    {
        FILE *p1 = fopen("./a.txt","r");
        FILE *p2 = fopen("./b.txt","w");
        char buf[1024] = {0};
        
        while(!feof(p1))
        {
            memset(buf,0,sizeof(buf));
            size_t res = fread(buf,sizeof(char),sizeof(buf),p1);
            code(buf,res);
            fwrite(buf,sizeof(char),res,p2);
        }
        fclose(p1);
        fclose(p2);
        return 0;
    }

    解密:

    /***
    decode.c
    ***/
    #include<stdio.h>
    #include<string.h>
    
    void decode(char *p,size_t n)
    {
        size_t i;
        for(i = 0; i < n; i++)
        {
            p[i] -= 3;
        }
    }
    
    int main()
    {
        FILE *p1 = fopen("./b.txt","rb");
        FILE *p2 = fopen("./c.txt","wb");
        char buf[1024] = {0};
        
        while(!feof(p1))
        {
            memset(buf,0,sizeof(buf));
            size_t res = fread(buf,sizeof(char),sizeof(buf),p1);
            decode(buf,res);
            fwrite(buf,sizeof(char),res,p2);
        }
        fclose(p1);
        fclose(p2);
        return 0;
    }
  • 相关阅读:
    tensorflow之tf.squeeze()
    tf.slice()
    tensorflow之tf.meshgrid()
    tensorflow: arg_scope()
    tf.ConfigProto()
    os.path.join()
    argparse.ArgumentParser()用法解析
    Flutter学习之ListView(1)
    Flutter学习之image
    Flutter学习之image
  • 原文地址:https://www.cnblogs.com/wanghao-boke/p/11222972.html
Copyright © 2011-2022 走看看