zoukankan      html  css  js  c++  java
  • 加密文件

    #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");
    }

  • 相关阅读:
    java-transaction事件
    Cookie,Session基础知识
    JSP基础笔记
    PHP----学生管理系统
    C语言程序设计-----贪吃蛇
    2019年数维杯三场征战赛
    回忆2018年高教杯数学建模大赛
    iPad横屏模式研究
    IOS UIWebView截获html并修改便签内容,宽度自适应
    如何保持iOS上键盘出现时输入框不被覆盖
  • 原文地址:https://www.cnblogs.com/xiaodaxiaonao/p/8699680.html
Copyright © 2011-2022 走看看