1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354:
| using System; using System.Collections.Generic; using System.Linq; using System.Text;
namespace ConsoleApplication1 { class Program { static byte[] _crypt = new byte[] { 179, 36, 206, 79, 64 };
static byte[] _real = new byte[] { 185, 130, 223 };
private static readonly short[] _duffmanTable = new short[] { 1, 2, 3, 4, 5, 0, 6, 7, 8, 9, 10, 11, 12, 13, -256, 14, 15, 16, 17, 18, 19, 20, 21, 22, -1, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, -64, 41, 42, 43, 44, -6, 45, 46, 47, 48, 49, 50, 51, -119, 52, -32, 53, 54, -14, 55, -5, 56, 57, 58, 59, 60, -2, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, -51, 73, 74, 75, 76, 77, -101, -111, -4, -97, 78, 79, -110, 80, 81, -116, 82, 83, 84, -255, 85, 86, 87, 88, 89, 90, -15, -10, 91, 92, -21, 93, -117, 94, 95, 96, 97, 98, 99, 100, -114, 101, -105, 102, -26, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, -3, 113, -7, 114, -131, 115, -144, 116, 117, -20, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, -100 , 130, -8, 131, 132, 133, 134, -120, 135, 136, -31, 137, 138, -109, -234, 139, 140, 141, 142, 143, 144, -112, 145, -19, 146, 147, 148, 149, -66, 150, -145, -13, -65, 151, 152, 153, 154, -30, 155, 156, 157, -99, 158, 159, 160, 161, 162, -23, 163, -29, 164, -11, 165, 166, -115, 167, 168, 169, 170, -16, 171, -34, 172, 173, -132, 174, -108, 175, -22, 176, -9, 177, -84, -17, -37, -28, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, -104, 188, -78, 189, -61, -79, -178, -59, -134, 190, -25, -83, -18, 191, -57, -67, 192, -98, 193, -12, -68, 194, 195, -55, -128, -24, -50, -70, 196, -94, -33, 197, -129, -74, 198, -82, 199, -56, -87, -44, 200, -248, 201, -163, -81, -52, -123, 202, -113, -48, -41, -122, -40, 203, -90, -54, 204, -86, -192, 205, 206, 207, -130, -53, 208, -133, -45, 209, 210, 211, -91, 212, 213, -106, -88, 214, 215, 216, 217, 218, -49, 219, 220, 221, 222, 223, 224, 225, 226, 227, -102, -160, 228, -46, 229, -127, 230, -103, 231, 232, 233, -60, 234, 235, -76, 236, -121, 237, -73, -149, 238, 239, -107, -35, 240, -71, -27, -69, 241, -89, -77, -62, -118, -75, -85, -72, -58, -63, -80, 242, -42, -150, -157, -139, -236, -126, -243, -142, -214, -138, -206, -240, -146, -204, -147, -152, -201, -227, -207, -154, -209, -153, -254, -176, -156, -165, -210, -172, -185, -195, -170, -232, -211, -219, -239, -200, -177, -175, -212, -244, -143, -246, -171, -203, -221, -202, -181, -173, -250, -184, -164, -193, -218, -199, -220, -190, -249, -230, -217, -169, -216, -191, -197, -47, 243, 244, 245, 246, 247, -148, -159, 248, 249, -92, -93, -96, -225, -151, -95, 250, 251, -241, 252, -161, -36, 253, 254, -135, -39, -187, -124, 255, -251, -162, -238, -242, -38, -43, -125, -215, -253, -140, -208, -137, -235, -158, -237, -136, -205, -155, -141, -228, -229, -213, -168, -224, -194, -196, -226, -183, -233, -231, -167, -174, -189, -252, -166, -198, -222, -188, -179, -223, -182, -180, -186, -245, -247, };
static void Main(string[] args) { int len = 0; byte[] back = Unpack(_crypt, 0, _crypt.Length, ref len);
Console.WriteLine("Rückgabe von unserer Methode:"); for (int i = 0; i < back.Length; i++) { Console.WriteLine(back[i]); }
Console.WriteLine("So sollte das aussehen:"); for (int i = 0; i < _real.Length; i++) { Console.WriteLine(_real[i]); }
Console.ReadLine(); }
public unsafe static byte[] Unpack(byte[] input, int offset, int count, ref int length) { if (input.Length == 0) return null;
byte[] output = new byte[input.Length * 4 + 4];
int bit_num = 8; int treepos = 0; int value = 0; int mask = 0; int len = input.Length; int dest_index = 0;
fixed (byte* pIntput = input) { byte* pStart = pIntput; while (true) { if (bit_num == 8) { if (len == 0) { return output; } len--; value = *pStart++; bit_num = 0; mask = 0x80; } if ((value & mask) == 0) treepos = _duffmanTable[treepos * 2]; else treepos = _duffmanTable[treepos * 2 + 1]; mask >>= 1; bit_num++;
if (treepos <= 0) { if (treepos == -256) { bit_num = 8; treepos = 0; continue; } output[dest_index++] = (byte)-treepos; treepos = 0; } } } } } } |