Skip to content

Instantly share code, notes, and snippets.

@khang06
Created April 19, 2021 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save khang06/bc9b20f2d813be8586a1d78917be5ca8 to your computer and use it in GitHub Desktop.
Save khang06/bc9b20f2d813be8586a1d78917be5ca8 to your computer and use it in GitHub Desktop.
MIDI decryption algorithm for Magic Tiles 3
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace mt3decrypt
{
class Program
{
static readonly string MIDIKey = "$jshHgdn123&Am@n0te3+x";
static void Main(string[] args)
{
var key = Encoding.UTF8.GetBytes(MIDIKey);
var sha256 = SHA256.Create();
var key_hash = sha256.ComputeHash(key);
var salt = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
var derive = new Rfc2898DeriveBytes(key_hash, salt, 1000);
var aes = new RijndaelManaged();
aes.KeySize = 256;
aes.BlockSize = 128;
aes.Key = derive.GetBytes(32);
aes.IV = derive.GetBytes(16);
aes.Mode = CipherMode.CBC;
var dec = aes.CreateDecryptor();
var input = File.ReadAllBytes("D:\\Someoneleaving.mid.encrypted");
var output = new byte[input.Length];
using (MemoryStream ms = new MemoryStream(input))
{
using (CryptoStream cs = new CryptoStream(ms, dec, CryptoStreamMode.Read))
{
cs.Read(output);
}
}
File.WriteAllBytes("D:\\Someoneleaving.mid", output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment