using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 雷神之锤暴力压缩算法
{public partial class Form1 : Form{public Form1(){InitializeComponent();}byte[] info = new byte[] { 0xAB, 0x05, 0x09, 0x15, 0x00, 0x0F };//1.首先1个字节变成两个字节,使得两个字节之和是byte[i],并且满足位置的奇数偶数,还要满足校验和,条件是先把倒数第三个字节转换为二进制,1是奇数,2是偶数string er = "";private void Form1_Load(object sender, EventArgs e){loadPrime();//初始化质数表er = Convert.ToString(info[info.Length - 3], 2);if (er.Length < (info.Length - 3) * 2){for (int i = 0; i < (info.Length - 3) * 2 - er.Length; i++){er = "0" + er; // er[]长度= 原始密文的长度-3)*2=6,如果长度不够,前面补0}}for (int m = 0; m < info.Length - 3; m++){textBox1.Text += info[m] + " GO...\r\n";for (int x = 0; x < 16; x++){for (int y = 0; y < 16; y++){//0 0if (x + y == info[m]){for (int z = m * 2; z < er.Length - 1; z++){int tmp=int.Parse(er[z].ToString());int yu=x%2;if (tmp==yu)if (y % 2 == int.Parse(er[z + 1].ToString()))textBox1.Text += "x=" + x + ",y=" + y + "\r\n";break;}}if (x * y == info[m]){//注意奇数是没有办法拆分为整数乘除,如果info[m]是一个质数,那么根据欧几里得原理,计算量就变小了//X+Y=INFO[M] 并且INFO[M]属于质数//那X=1,Y=INFO[M]-1 或者 Y=1,X=INFO[M]-1textBox2.Text += "x=" + x + ",y=" + y + "\r\n";}}}}}Dictionary<int, int> prs = new Dictionary<int, int>();private void loadPrime(){prs.Add(2, 0);prs.Add(3, 0);prs.Add(5, 0);prs.Add(7, 0);prs.Add(11, 0);prs.Add(13, 0);prs.Add(17, 0);prs.Add(19, 0);prs.Add(23, 0);prs.Add(29, 0);prs.Add(31, 0);prs.Add(37, 0);prs.Add(41, 0);prs.Add(43, 0);prs.Add(47, 0);prs.Add(53, 0);prs.Add(59, 0);prs.Add(61, 0);prs.Add(67, 0);prs.Add(71, 0);prs.Add(73, 0);prs.Add(79, 0);prs.Add(83, 0);prs.Add(89, 0);prs.Add(97, 0);prs.Add(101, 0);prs.Add(103, 0);prs.Add(107, 0);prs.Add(109, 0);prs.Add(113, 0);prs.Add(127, 0);prs.Add(131, 0);prs.Add(137, 0);prs.Add(139, 0);prs.Add(149, 0);prs.Add(151, 0);prs.Add(157, 0);prs.Add(163, 0);prs.Add(167, 0);prs.Add(173, 0);prs.Add(179, 0);prs.Add(181, 0);prs.Add(191, 0);prs.Add(193, 0);prs.Add(197, 0);prs.Add(199, 0);prs.Add(211, 0);prs.Add(223, 0);prs.Add(227, 0);prs.Add(229, 0);prs.Add(233, 0);prs.Add(239, 0);prs.Add(241, 0);prs.Add(251, 0);}List<string> cache = new List<string>();List<byte[]> cacheint = new List<byte[]>();private void five(List<string> info){for (int i = 0; i < info.Count; i++){ for (int j = 0; j < info.Count; j++){for (int k = 0; k < info.Count; k++){//for (int x = 0; x < info.Count; x++)//{byte[] hex = new byte[3];hex[0] = Convert.ToByte(info[i], 16);hex[1] = Convert.ToByte(info[j], 16);hex[2] = Convert.ToByte(info[k], 16);//hex[3] = Convert.ToByte(info[x], 16);cacheint.Add(hex);//}}}}textBox2.Text = "ok";}private void four(){string[] info = new string[] { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" };List<string> all=new List<string>();for (int i = 0; i < info.Length; i++){for (int j = 0; j < info.Length; j++){all.Add(info[i]+info[j]);}}five(all);textBox2.Text = "ok";}private void back(List<string> info){for (int i = 0; i < info.Count; i++){for (int j = 0; j < info.Count; j++){for (int k = 0; k < info.Count; k++){for (int x = 0; x < info.Count; x++){for (int y = 0; y < info.Count; y++){for (int z = 0; z < info.Count; z++){for (int a = 0; a < info.Count; a++){for (int b = 0; b < info.Count; b++){byte[] hex = new byte[] { };byte hexb = Convert.ToByte(info[b], 16);//hex[0] = Convert.ToByte(info[i] + info[j], 16);//hex[1] = Convert.ToByte(info[k] + info[x], 16);//hex[2] = Convert.ToByte(info[y] + info[z], 16);//hex[2] = Convert.ToByte(info[a] + info[b], 16);cacheint.Add(hex);}}}}}}}}textBox2.Text = "ok";}}
}
此算法的好处是有很大概率将一串2进制数据压缩为更大的串