from Tkinter import *
from tkFileDialog import askopenfilename
import struct
filename = askopenfilename()
if len(filename) == 0:
exit()
outputfilename = filename[:-4] + '.txt'
#outputfilename = filename[:-4] + '.ndt'
f = open(filename, 'rb')
buf = f.read()
f.close()
HEADER_SIZE = 0x18 #i don't know this :D it's hex that mean 18?
seed = struct.unpack('<H', buf[12:14])[0]
#seed = struct.pack('<H', buf[12:14])[0]
output = []
for i in xrange(HEADER_SIZE, len(buf)-1):
v = struct.unpack('<B', buf[i])[0]
#v = struct.pack('<B', buf[i])[0]
v -= seed
v = v & 0xFF
b2 = struct.unpack('<B', buf[i+1])[0]
#b2 = struct.pack('<B', buf[i+1])[0]
x = v ^ b2
output.append(x)
f = open(outputfilename, 'wb')
for v in output:
f.write(struct.pack('B', v)[0])
f.close()
exit()