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
| from ctypes import * encode = [0x90,0xe2,0xf1,0x44,0x94,0xa1,0xf8,0xdb,0x5e,0xfb,0x3a,0x68,0xf9,0xb4,0xbe,0x61,0x69,0x8c,0x1d,0x47,0x89,0x0f,0x56,0xd2,0x63,0x4c,0x53,0x4f,0xf4,0xbf,0x74,0x68,0x71,0x8e,0x89,0xa8,0xaf,0x57,0x46,0xbc,0x2e,0xb2,0xdb,0xcf,0xe5,0x94,0x08,0x2e,0xc4,0xee,0xaf,0x41,0x8a,0x41,0x42,0x0d,0x38,0x7f,0x38,0xe9,0xf4,0x27,0xcb,0x1c,0x1c,0x5a,0xd3,0xe2,0xde,0xc1,0xe5,0x31,0xe3,0x51,0x7d,0x64,0x82,0x08,0xb3,0x20,0x96,0x2f,0xee,0x4a,0x4a,0xcb,0xf0,0x04,0x76,0x44,0x32,0x3e,0x48,0xcc,0x67,0xdc,0x62,0x7f,0x3b,0xab,0x1d,0x7c,0x99,0xcf,0x2a,0xd2,0xc3,0xc5,0xb6,0x86,0x9a,0x93,0x84,0x51,0xe2,0xd1,0xa2,0xa6,0x4b,0xfe,0xf4,0x21,0x8e,0x73,0xa7,0x6f,0x45,0xa7,0x88,0xde,0x67,0x51,0xfa,0xd9,0x55,0xb6,0x63,0x1b,0xa4,0x02,0x4c,0x3e,0x00,0xa7,0xfc,0x4d,0x42,0x35,0x18,0x2a,0x5e,0x58,0x5d,0x7a,0x6d,0x21,0x55,0xa4,0x54,0xe0,0x77,0xb3,0xce,0xe4,0x4c,0xce,0x1a,0x28,0xe7,0xf9,0x64,0x60,0xa5,0xed,0x2c,0xc8,0xfd,0x94,0x24,0xdf,0x44,0x45,0x3a,0xb8,0x95,0x9a,0x0c,0xab,0x52,0x3f,0x5c,0x0c,0xbe,0xae,0xbf,0x6b,0x62,0x46,0x45,0x23,0x9f,0x63,0x70,0x94,0xb7,0xdd,0x46,0xf7,0x06,0xb9,0x7b,0xd5,0x6c,0x04,0xe4,0xf4,0x47,0x73,0x07,0x09,0x75,0x17,0xfc,0x13,0x93,0xac,0x8a,0x6d,0x61,0xbf,0x0f,0x0a,0x07,0xc9,0x7f,0x0b,0xcc,0xf2,0x97,0xa6,0x25,0x8d,0x02,0x40,0xb0,0xdb,0x51,0x34,0x70,0x32,0x67,0xd5,0xf4,0xe6,0xe4,0x95,0xf9,0xe6,0x1a,0xc0,0xbd,0xb2,0x8a,0x30,0xd9,0x78,0x95,0x59,0x30,0xf7,0x0f,0x97,0x4e,0x99,0x32,0x76,0x5e,0xc3,0x12,0x3b,0x53,0x4b,0x4f,0x7b,0xee,0x5d,0xf9,0x5d,0x4d,0xae,0x31,0xfc,0xe3,0x74,0x3e,0xcf,0x46,0x3a,0x6a,0x31,0x99,0xec,0xac,0xe5,0xf8,0xa0,0x6c,0xe2,0xdf,0x4f,0x69,0xff,0xeb,0xeb,0x25,0x16,0x38,0xf2,0x58,0x86,0x84,0xe8,0x6a,0xc5,0x0b,0x30,0xd4,0xd2,0x14,0xe9,0xfa,0x95,0x20,0x30,0x0d,0x5a,0xe4,0x3a,0x95,0x60,0xbf,0x57,0x7e,0x31,0x98,0xa1,0x71,0xa2,0x2b,0x28,0x40,0x2b,0xe2,0x3e,0x80,0x89,0x7a,0x5e,0x3f,0xf2,0x67,0x79,0x97,0x67,0x8f,0x07,0xf8,0xe0,0x4c,0x51,0xfa,0x72,0x59,0xc5,0xb9,0x73,0x97,0xf1,0x3e,0x29,0x35,0xd1,0x31,0x66,0x4f,0x1b,0x20,0xc1,0xeb,0x5a,0x99,0x0b,0x62,0x10,0x3e,0x98,0xa5,0xfb,0xaf,0xce,0x4b,0xde,0x07,0x23,0x17,0xf0,0x88,0x1d,0x95,0xe1,0x07,0x9e,0xf0,0xee,0xf6,0xff,0xf4,0x9c,0x5b,0x6e,0x36,0xf6,0xd5,0xef,0x61,0xb6,0x16,0xb9,0x85,0x44,0xd4,0x25,0xf2,0x88,0x34,0x51,0x88,0xf0,0xf8,0x90,0xab,0x83,0xb6,0xc8,0x21,0xf1,0xb7,0x25,0xfc,0x15,0xee,0xd3,0x70,0x23,0xbb,0x05,0xba,0x6d,0x0d,0x4b,0x35,0x2b,0xf1,0xb6,0x33,0x65,0x5e,0x58,0x5b,0x64,0xd4,0x19,0x73,0x36,0xec,0x22,0x36,0x7e,0x9c,0xf1,0xe1,0xc2,0x80,0xfe,0x63,0xd8,0x99,0x25,0x63,0x49,0xa0,0xf0,0xe1,0xce,0xdf,0xfe,0x9a,0xe7,0x88,0x7f,0x38,0x3f,0xbc,0x11,0xc8,0xec,0x83,0xd0,0xbe,0x6c,0x5b,0xfc,0xcf,0x3c,0x5d,0x1a,0xa9,0xa1,0xe7,0x78,0x53,0xd4,0xc3,0xe9,0x31,0x74,0x8c,0xdb,0xe1,0x72,0x7c,0x4f,0x35,0x95,0x56,0xf5,0x7e,0x9a,0x0d,0xb3,0x35,0x9d,0x6d,0xab,0xea,0x66,0x41,0x70,0x22,0x6a,0xb7,0x33,0x40,0xf7,0x8d,0x1c,0x05,0x1c,0xce,0xd9,0x94,0x68,0x9e,0x7e,0x26,0x8e,0x86,0xaa,0x0f,0x20,0x7f,0xc1,0x22,0x14,0x74,0xd0,0x1c,0x15,0x92,0x75,0x42,0x7a,0xc9,0x12,0x53,0x22,0x36,0x8b,0x6a,0x93,0x22,0xdb,0x13,0x83,0x46,0x31,0x93,0x69,0x0e,0x09,0xe7,0xd3,0x42,0x21,0x5b,0xe2,0xeb,0x3b,0x28,0x05,0x1e,0xf2,0xaa,0x5f,0xc6,0x09,0xb2,0x8f,0x64,0x6b,0x10,0x4a,0x51,0x80,0x3c,0x44,0x96,0x72,0x9a,0x41,0xd7,0x3d,0x46,0xcb,0xed,0x54,0xcf,0x04,0x1b,0x2b,0x4b,0x58,0x3b,0xb1,0x10,0x02,0x18,0x65,0x1e,0x1f,0xb8,0x75,0x02,0xca,0x53,0x06,0x5d,0x0c,0xbc,0x76,0xa2,0x9f,0x3d,0x57,0x5c,0xe6,0xb3,0x0e,0xfa,0xe9,0xe7,0x82,0x30,0x26,0xae,0x5c,0x2b,0x92,0x18,0xd0,0x43,0x4d,0x21,0xf1,0xce,0x55,0x6c,0x98,0x29,0x4a,0xf6,0xc4,0x1f,0x9b,0x73,0x1e,0xa8,0x75,0x3e,0xc3,0x9c,0xe0,0x7d,0x6a,0xb5,0x81,0x05,0x43,0x6b,0xc0,0xe5,0xb5,0xcf,0x27,0xf6,0x59,0xc0,0x58,0x84,0xf0,0xe9,0x6a,0x83,0xa2,0x1a,0x3d,0x25,0x7e,0x43,0xa4,0x8d,0x93,0xb0,0xb4,0x01,0x90,0xdc,0xc3,0xaa,0x9c,0x1c,0x4d,0x72,0x0c,0x13,0x6b,0x98,0x77,0xe7,0xa4,0x52,0x79,0x8f,0x2a,0x6d,0x79,0x02,0xc4,0x99,0xb9] encode2 = [0x52,0x45,0x4c,0x70,0xda,0x43,0x2d,0x67,0xd6,0x02,0x4e,0x0d,0x32,0x70,0x75,0xcc,0x1f,0xa2,0xde,0x71,0x97,0x05,0x86,0x01,0xd1,0xa6,0xb1,0x60,0x66,0xaf,0x95,0xe2,0x70,0xd8,0x70,0xce,0x1d,0xd4,0x79,0x9a,0x6e,0xc0,0x23,0xf2,0xe0,0xdb,0xe7,0x05,0xc8,0xaa,0x7a,0xd8,0x16,0x87,0x95,0xf5,0x05,0xf8,0xd2,0x21,0x61,0xe2,0x99,0x38,0x33,0xd8,0x3d,0xc6,0x54,0x04,0x46,0xf1,0x86,0xa2,0xe6,0x8b,0x15,0x0b,0x26,0xe8,0xd1,0x01,0x89,0xf7,0xf5,0x71,0x23,0x41,0x08,0x10,0x10,0x86,0x0d,0x2b,0x3a,0x68,0xcc,0xe4,0xbb,0x87,0x49,0xa5,0x17,0xa8,0x12,0x4a,0xa9,0x16,0x0f,0x01,0x3a,0x05,0x62,0xed,0xc7,0x55,0xa5,0x37,0x17,0x31,0xdf,0x9c,0x2b,0x6e,0xed,0xfe,0x7c,0x6d,0x91,0x3a,0x18,0xf5,0x2e,0x7e,0xd4,0x81,0xb3,0xcb,0xe0,0xfe,0xed,0x43,0x88,0x3a,0x0e,0x29,0xf1,0x0d,0x65,0x38,0xeb,0x87,0xd0,0x8a,0xc5,0x0d,0x1e,0x83,0x80,0xda,0x3e,0xcf,0xec,0x11,0xc6,0xe7,0x2a,0x83,0x37,0x08,0x21,0x0f,0x86,0x63,0x16,0x4d,0xb3,0x53,0x50,0x7a,0xf3,0x48,0x20,0x7b,0xf3,0x2f,0x9a,0x77,0xaa,0x00,0xd2,0x50,0x60,0x9c,0x65,0x6a,0x37,0x28,0x70,0x57,0xb9,0xc9,0x12,0x6e,0x8a,0xc5,0x08,0x40,0x90,0xe1,0xbf,0x52,0x3b,0x06,0xa9,0x6c,0x5d,0x02,0xd7,0x3a,0xb1,0x9b,0x42,0x9a,0xde,0x7d,0x1d,0x58,0xa6,0x18,0xa9,0x74,0xab,0x96,0x89,0xa3,0x6d,0x8f,0xa4,0x93,0x12,0x67,0xd0,0xb5,0xff,0x21,0x8a,0x69,0xca,0x40,0xca,0x78,0x4f,0x57,0x26,0xd7,0x95,0x80,0x50,0xc2,0x7f,0xad,0x23,0x2f,0xab,0x7b,0xc8,0xda,0x5d,0xc6,0x77,0xb7,0xc2,0x6f,0xbd,0x7f,0xe3,0xd2,0x37,0xe9,0x67,0xde,0x42,0x40,0xf6,0x73,0xff,0xb5,0x81,0x2a,0x07,0x98,0xbf,0x7f,0xbf,0x15,0x28,0xcb,0xf9,0xc7,0xe7,0x0e,0x70,0xc5,0x4b,0x42,0x20,0x06,0x1c,0x14,0x1c,0x77,0xe3,0x5d,0x8b,0x12,0x22,0x4b,0xda,0xbe,0xd0,0x99,0x87,0x76,0x1f,0xce,0x57,0xf9,0x11,0x12,0xb3,0xd3,0xcb,0x4f,0xd9,0x0c]
def bytes_to_dwords(byte_list): return [(byte_list[i] | (byte_list[i+1] << 8) | (byte_list[i+2] << 16) | (byte_list[i+3] << 24)) for i in range(0, len(byte_list), 4)]
def dwords_to_bytes(dword_list): return [byte & 0xff for dword in dword_list for byte in (dword, dword >> 8, dword >> 16, dword >> 24)]
def xxtea_encrypt(data, length, key): data = bytes_to_dwords(data) last = c_uint32(data[length-1]) rounds = 0x34 // length + 6 delta_sum = c_uint32(0) while rounds > 0: delta_sum.value -= 0x61c8864f key_index = (delta_sum.value >> 2) & 3 for i in range(length-1): next_data = c_uint32(data[i+1]) temp = c_uint32() temp.value = data[i] + (((last.value ^ key[key_index ^ i & 3]) + (next_data.value ^ delta_sum.value)) ^ (((16 * last.value) ^ (next_data.value >> 3)) + ((4 * next_data.value) ^ last.value >> 6))) data[i] = temp.value last = temp temp = c_uint32() temp.value = data[length-1] + (((last.value ^ key[key_index ^ (length-1) & 3]) + (data[0] ^ delta_sum.value)) ^ (((16 * last.value) ^ (data[0] >> 3)) + ((4 * data[0]) ^ last.value >> 6))) data[length-1] = temp.value last = temp rounds -= 1 return data
def xxtea_decrypt(data, length, key): data = bytes_to_dwords(data) rounds = 0x34 // length + 6 delta_sum = c_uint32(0 - rounds * 0x61c8864f) while rounds > 0: key_index = (delta_sum.value >> 2) & 3 for i in range(length-1, 0, -1): prev_data = c_uint32(data[i-1]) temp = c_uint32() temp.value = data[i] - (((prev_data.value ^ key[key_index ^ i & 3]) + (data[(i+1) % length] ^ delta_sum.value)) ^ (((16 * prev_data.value) ^ (data[(i+1) % length] >> 3)) + ((4 * data[(i+1) % length]) ^ prev_data.value >> 6))) data[i] = temp.value temp = c_uint32() temp.value = data[0] - (((data[length-1] ^ key[key_index ^ 0 & 3]) + (data[1] ^ delta_sum.value)) ^ (((16 * data[length-1]) ^ (data[1] >> 3)) + ((4 * data[1]) ^ data[length-1] >> 6))) data[0] = temp.value delta_sum.value += 0x61c8864f rounds -= 1 return data
if __name__ == '__main__': key = [0x64,0x36,0x63,0x39,0x30,0x32,0x63,0x36,0x65,0x33,0x66,0x63,0x35,0x66,0x32,0x62] decrypted = xxtea_decrypt(encode, len(encode)//4, bytes_to_dwords(key)) for i in dwords_to_bytes(decrypted): print(chr(i), end='') print()
|