首页
论坛
课程
招聘
[原创]2019CTF第十题writeup
2019-3-11 11:38 790

[原创]2019CTF第十题writeup

2019-3-11 11:38
790
直接写加解密算法代码好了:

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace CSharpConsoleApp1
{
  class Program
  {
    static void Main(string[] args)
    {
      Console.WriteLine("Please Input Serial:");
      string s = a(Console.ReadLine(), "Kanxue2019");
      s = b(Console.ReadLine(), "Kanxue2019");
      if ( s== "4RTlF9Ca2+oqExJwx68FiA==")
      {
        Console.WriteLine("Congratulations!  : )");
        Console.ReadLine();
      }
    }

    public static string a(string A_0, string A_1)
    {
      byte[] bytes = Encoding.UTF8.GetBytes("Kanxue2019CTF-Q1");
      byte[] buffer = Encoding.UTF8.GetBytes(A_0);
      byte[] rgbKey = new PasswordDeriveBytes(A_1, null).GetBytes(0x20);
      RijndaelManaged managed1 = new RijndaelManaged();
      managed1.Mode = CipherMode.CBC;
      ICryptoTransform transform = managed1.CreateEncryptor(rgbKey, bytes);
      MemoryStream stream = new MemoryStream();
      CryptoStream stream1 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
      stream1.Write(buffer, 0, buffer.Length);
      stream1.FlushFinalBlock();
      byte[] inArray = stream.ToArray();
      stream.Close();
      stream1.Close();
      return Convert.ToBase64String(inArray);
    }
    public static string b(string A_0, string A_1)
    {
      string s = "4RTlF9Ca2+oqExJwx68FiA==";
      byte[] buffer = Convert.FromBase64String(s);



      byte[] bytes = Encoding.UTF8.GetBytes("Kanxue2019CTF-Q1");
      //byte[] buffer = Encoding.UTF8.GetBytes(A_0);
      byte[] rgbKey = new PasswordDeriveBytes(A_1, null).GetBytes(0x20);
      RijndaelManaged managed1 = new RijndaelManaged();
      managed1.Mode = CipherMode.CBC;
      ICryptoTransform transform = managed1.CreateDecryptor(rgbKey, bytes);
      MemoryStream stream = new MemoryStream();
      CryptoStream stream1 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
      stream1.Write(buffer, 0, buffer.Length);
      stream1.FlushFinalBlock();
      byte[] inArray = stream.ToArray();
      string s1=Encoding.UTF8.GetString(inArray);
      Console.Write(s1);
      stream.Close();
      stream1.Close();
      return Convert.ToBase64String(inArray);
    }
  }
}



[培训]12月3日2020京麒网络安全大会《物联网安全攻防实战》训练营,正在火热报名中!地点:北京 · 新云南皇冠假日酒店

收藏
点赞0
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回