教学服务系统

 找回密码
 立即注册
搜索
查看: 570|回复: 0

信息计算2019级2班32号王诗琪

[复制链接]

8

主题

16

帖子

114

积分

注册会员

Rank: 2

积分
114
发表于 2022-4-15 21:13:14 | 显示全部楼层 |阅读模式
前提
    1.导入老师所给文件:3des.cs,加入命名空间threeDes,便于其他文件引用。
    2.软件:vs code
过程
     1.加密文件
     加密代码如下:
  1. using System;
  2. using threeDes;
  3. namespace ConsoleApplication1
  4. {
  5.     class encode
  6.     {  
  7.         static void Main(string[] args)
  8.         {
  9.           //秘钥
  10.           string sKey = "qJzGEh6hESZDVJeCnFPGuxzaiB7NLQM5";
  11.           //调用IV有值的构造函数
  12.           TripleDES_ a =new TripleDES_(sKey);         
  13.           Console.WriteLine("请输入待加密文件名:(绝对路径)");
  14.           string input = Console.ReadLine();
  15.           Console.WriteLine("请输入存储文件名:(绝对路径)");
  16.           string output = Console.ReadLine();
  17.           a.Encrypt(input, output);
  18.           Console.WriteLine("执行成功。");
  19.     }
  20.   }
  21. }
复制代码
   运行界面:


    E盘里:

    文件内容:(此处加密文件为乱码,找了很多方法没有解决这个问题)


    2.解密文件
    解密文件代码如下:
  1. using System;
  2. using threeDes;
  3. namespace ConsoleApplication2
  4. {
  5.     class decode
  6.     {  
  7.         static void Main(string[] args)
  8.         {
  9.           //秘钥
  10.           string sKey = "qJzGEh6hESZDVJeCnFPGuxzaiB7NLQM5";
  11.           //调用IV有值的构造函数
  12.           TripleDES_ a =new TripleDES_(sKey);         
  13.           Console.WriteLine("请输入待解密文件名:(绝对路径)");
  14.           string input = Console.ReadLine();
  15.           Console.WriteLine("请输入存储文件名:(绝对路径)");
  16.           string output = Console.ReadLine();
  17.           a.Decrypt(input, output);
  18.           Console.WriteLine("执行成功。");
  19.     }
  20.   }
  21. }
复制代码
   运行界面:

    E盘里:

    文件内容:(为了方便,待解密文件取上述得到的加密文件)

总结
    1.通过代码导出的文件内容为乱码,初步分析问题为txt解析中文用的是gb2312,与VS code的不一致,但没有找到解决办法。
    2.因为要执行加密程序和解密文件,而两个都是用main方法写成,因此在运行其中一个时,要注释掉另一个文件内容。否则会提示:
      
    3.加密和解密代码虽然可以成功执行,但实际上还是有关于输入与输出语句的警告:
     
    4.在调试代码时,出现了这样的弹窗错误:
     ${workspaceFolder}/bin/Debug/insert-target-framework-here/insert-project-name-here.dll不存在
      需要在launch.json中吧“Program”改为如下内容即可:
      



本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

教学服务系统

GMT+8, 2025-4-30 07:42 , Processed in 0.015330 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表