[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Windows.Forms;
namespace MX_keygen
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static double log10(ulong x)
{
return Math.Log(x) / Math.Log(10.0);
}
public static string Encoder(ulong str)
{
string text = "";
for (int i = (int)Math.Floor(log10(str) / log10(62UL)); i >= 0; i--)
{
int num = (int)Math.Floor(str / Math.Pow(62.0, (double)i));
text +=keyaaa[num].ToString();
str -= (ulong)((double)num * Math.Pow(62.0, (double)i));
}
return text;
}
public static ulong Decoder(string str)
{
ulong num = 0UL;
int num2 = str.Length - 1;
for (int i = 0; i <= num2; i++)
{
num += (ulong)((long)keyaaa.IndexOf(str.Substring(i, 1).ToCharArray()[0]) * (long)((ulong)Math.Pow(62.0, (double)(num2 - i))));
}
return num;
}
private static List<char> keyaaa = new List<char>
{
'v',
'P',
'h',
'7',
'z',
'Z',
'w',
'A',
'2',
'L',
'y',
'U',
'4',
'b',
'G',
'q',
'5',
't',
'c',
'V',
'f',
'I',
'M',
'x',
'J',
'i',
'6',
'X',
'a',
'S',
'o',
'K',
'9',
'C',
'N',
'p',
'0',
'O',
'W',
'l',
'j',
'Y',
'T',
'H',
'Q',
'8',
'R',
'E',
'n',
'm',
'u',
'3',
'1',
'B',
'r',
'd',
'g',
'e',
'D',
'k',
'F',
's'
};
public static string MD5Encrypt32(string password)
{
string text = "";
byte[] array = MD5.Create().ComputeHash(Encoding.UTF8.GetBytes(password));
for (int i = 0; i < array.Length; i++)
{
text += array[i].ToString("X2");
}
return text;
}
protected ulong[] Crc32Table;
public void GetCRC32Table()
{
Crc32Table = new ulong[256];
for (int i = 0; i < 256; i++)
{
ulong num = (ulong)i;
for (int num2 = 8; num2 > 0; num2--)
{
num = (((num & 1) != 1) ? (num >> 1) : ((num >> 1) ^ 0xEDB88320u));
}
Crc32Table[i] = num;
}
}
public ulong GetCRC32Str(string sInputString)
{
GetCRC32Table();
byte[] bytes = Encoding.ASCII.GetBytes(sInputString);
ulong num = 4294967295uL;
int num2 = bytes.Length;
for (int i = 0; i < num2; i++)
{
num = (num >> 8) ^ Crc32Table[(num & 0xFF) ^ bytes[i]];
}
return num ^ 0xFFFFFFFFu;
}
private void button1_Click(object sender, EventArgs e)
{
string sInputString = MD5Encrypt32(textBox1.Text.Substring(6,32));
ulong num = GetCRC32Str(sInputString);
if (num < 268435456)
{
num += 268435456;
}
string value = Encoder(num);
textBox2.Text = value;
}
}
}