Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
57 lines (42 sloc) 3.04 KB
import array
import struct
from ctypes import *
# TEA algo
def decipher(rounds, v, k):
delta = c_uint32(0x9E3779B9)
sum = c_uint32((delta.value*rounds) & 0xFFFFFFFF)
v0 = c_uint32(v[0])
v1 = c_uint32(v[1])
while rounds > 0:
v1.value -= (((((v0.value << c_uint32(4).value) ^ (v0.value >> c_uint32(5).value))) + v0.value) ^ (sum.value + c_uint32(key[(sum.value>>c_uint32(11).value) & 3]).value))
sum.value -= delta.value
v0.value -= ((((v1.value << c_uint32(4).value) ^ (v1.value >> c_uint32(5).value)) + v1.value) ^ (sum.value + c_uint32(key[sum.value & 3]).value))
rounds -= 1
return (v0.value, v1.value)
data = array.array('B', [0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A, 0x69, 0x03, 0x23, 0x4B, 0x73, 0x2F, 0xDC, 0xEF,
0x4E, 0x19, 0x14, 0x7F, 0x8F, 0xF1, 0x02, 0x7A, 0x67, 0xD7, 0x1D, 0xFA, 0x52, 0x94, 0xDE, 0x07,
0x7A, 0x56, 0x28, 0xF3, 0xD5, 0x69, 0x99, 0xB5, 0x68, 0x67, 0x2B, 0xAA, 0x30, 0x3A, 0x13, 0xF0,
0x42, 0x59, 0xC2, 0xD0, 0x61, 0x45, 0xB7, 0xF6, 0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A,
0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A, 0xCD, 0xE1, 0x77, 0x54, 0x0A, 0xCD, 0xD4, 0x4D,
0x35, 0x9E, 0x0A, 0xE7, 0x7F, 0x37, 0xEB, 0x77, 0x99, 0xF2, 0xCA, 0x05, 0x4D, 0xA8, 0x01, 0x6E,
0xB6, 0x79, 0x85, 0xD0, 0x5B, 0xB6, 0x68, 0x03, 0x31, 0x73, 0x9B, 0xB2, 0x63, 0xF3, 0xC4, 0x1E,
0xD1, 0x06, 0x4D, 0x49, 0x05, 0xEC, 0x5F, 0x3A, 0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A,
0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A, 0xAC, 0x9F, 0x9B, 0xAF, 0x15, 0xBD, 0x3E, 0x90,
0x9F, 0x2E, 0x29, 0xEA, 0x5D, 0x0F, 0xC1, 0x74, 0xB3, 0xA3, 0xE2, 0xD7, 0x71, 0x82, 0xA8, 0x8B,
0xC0, 0xE9, 0xAA, 0x4E, 0xBF, 0x08, 0x72, 0x04, 0xE7, 0x90, 0x14, 0x75, 0x6B, 0x94, 0x1D, 0xE3,
0x3C, 0xFE, 0x34, 0xB4, 0x9A, 0x28, 0xC0, 0x35, 0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A,
0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A, 0xE7, 0xC0, 0xAE, 0x94, 0x8A, 0xD8, 0x12, 0xF2,
0x54, 0xB6, 0xA6, 0x9A, 0x66, 0x21, 0xA5, 0xD3, 0x65, 0xEB, 0xE9, 0x0E, 0x2E, 0xD9, 0xE8, 0xB4,
0x4B, 0x84, 0xFA, 0xEC, 0x52, 0x50, 0x35, 0x8E, 0x32, 0x0C, 0xAB, 0x93, 0xDD, 0x24, 0x54, 0x04,
0xD5, 0x99, 0xF9, 0x44, 0xE4, 0x9E, 0xC2, 0xE4, 0x3E, 0xE6, 0xF0, 0xD0, 0xD5, 0x41, 0x8B, 0x8A])
for i in range(0xFFFF):
# expand hash to 128 bits
key = array.array('L', [(i << 16) | i, (i << 16) | i, (i << 16) | i, (i << 16) | i])
decrypted = bytearray()
for block in range(len(data)//8):
z = data[block * 8:block * 8 + 8]
x = decipher(32, struct.unpack('LL', z), key)
decrypted += struct.pack('LL', x[0], x[1])
f = open('{0:04X}.bin'.format(i), 'wb')
f.write(decrypted)
f.close()