• 加密文件


    #include<stdio.h>
    #include<stdlib.h>
    void main() {
     //复制一个文件,需要输入两个数据。  一个是被复制的文件,一个是需要复制到哪里。
     //加密程序其实已经完成了70%。
     char l_in_path[200] = { 0 };
     char l_out_path[200] = { 0 };
     char l_pass[50] = { 0 };
     int l_tools = NULL;

     printf("请输入源文件路径:");
     scanf("%s", l_in_path);
     printf("请输入新文件路径:");
     scanf("%s", l_out_path);
     printf("请输入密码:");
     scanf("%s", l_pass);

     printf("输入1为加密,输入2为解密:");
     scanf("%d", &l_tools);
     if (l_tools != 1 && l_tools != 2) {
      printf("功能输入选择错误 ");
      return;
     }
     FILE * l_fp_read = fopen(l_in_path, "rb");
     FILE * l_fp_write = fopen(l_out_path, "wb");

     if (l_fp_read != NULL && l_fp_write != NULL) {
      if (l_tools == 1) {
       char l_temp = fgetc(l_fp_read);
       while (feof(l_fp_read) == 0) {
        l_temp = l_temp + 40;
        fputc(l_temp, l_fp_write);
        l_temp = fgetc(l_fp_read);
       }
      }
      else {
       char l_temp = fgetc(l_fp_read);
       while (feof(l_fp_read) == 0) {
        l_temp = l_temp - 40;
        fputc(l_temp, l_fp_write);
        l_temp = fgetc(l_fp_read);
       }
      }


     }
     fclose(l_fp_read);
     fclose(l_fp_write);
     printf("已复制成功 ");
     system("pause");
    }


    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h>
    void main() {
     //复制一个文件,需要输入两个数据。  一个是被复制的文件,一个是需要复制到哪里。
     //加密程序其实已经完成了70%。
     char l_in_path[200] = { 0 };
     char l_out_path[200] = { 0 };
     char l_pass[50] = { 0 };
     int l_tools = NULL;

     printf("请输入源文件路径:");
     scanf("%s", l_in_path);
     printf("请输入新文件路径:");
     scanf("%s", l_out_path);
     printf("请输入密码:");
     scanf("%s", l_pass);

     printf("输入1为加密,输入2为解密:");
     scanf("%d", &l_tools);
     if (l_tools != 1 && l_tools != 2) {
      printf("功能输入选择错误 ");
      return;
     }


     FILE * l_fp_read = fopen(l_in_path, "rb");
     FILE * l_fp_write = fopen(l_out_path, "wb");
     int l_length = strlen(l_pass);
     int l_count = 0;

     if (l_fp_read != NULL && l_fp_write != NULL) {
      if (l_tools == 1) {
       char l_temp = fgetc(l_fp_read);
       while (feof(l_fp_read) == 0) {
        l_temp = l_temp ^ l_pass[l_count];
        l_temp = l_temp + l_count;
        l_count++;
        if (l_count == l_length) {
         l_count = 0;
        }

        fputc(l_temp, l_fp_write);
        l_temp = fgetc(l_fp_read);
       }
      }
      else {
       char l_temp = fgetc(l_fp_read);
       while (feof(l_fp_read) == 0) {
        l_temp = l_temp - l_count;
        l_temp = l_temp ^ l_pass[l_count];
        l_count++;
        if (l_count == l_length) {
         l_count = 0;
        }
        fputc(l_temp, l_fp_write);
        l_temp = fgetc(l_fp_read);
       }
      }


     }
     fclose(l_fp_read);
     fclose(l_fp_write);
     if (l_tools == 1) {
      printf("已加密成功 ");
     }
     else {
      printf("已解密成功 ");
     }

     system("pause");
    }

  • 相关阅读:
    写了这么久前端,你知道浏览器原理吗?
    史上最全的web前端开发程序员学习清单!
    常见前端面试题及答案
    “下辈子再也不当程序员了,我被黑够了”
    什么是web前端,全栈工程师就业前景怎么样?
    要嫁就嫁程序员,钱多话少死得早!
    想转行做web前端工程师,必学这6大技能
    测试用例设计总结
    python读取一个英文文件,并记录每个单词出现的次数,降序输出
    python读取一个文件的每一行判断是否为素数,并把结果写到另一个文件中
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/8699680.html
Copyright © 2020-2023  润新知