From 5f396c7637558df8ee23c90c8a2ad1b01885e686 Mon Sep 17 00:00:00 2001 From: Aram Date: Tue, 30 May 2017 23:18:04 +0200 Subject: [PATCH] Added bin/txt converters --- bintotxt.py | 16 ++++++++++++++++ txttobin.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 bintotxt.py create mode 100644 txttobin.py diff --git a/bintotxt.py b/bintotxt.py new file mode 100644 index 0000000..7631e07 --- /dev/null +++ b/bintotxt.py @@ -0,0 +1,16 @@ +import sys +data = file(sys.argv[1], 'rb').read() +uid = data[0:4] + +def parity(x): + return ("{0:08b}".format(x).count('1') & 1) + +for idx in range(6, len(data), 9): + n = data[idx:idx+8] + p = data[idx+8] + nonce_string = [ "%02x" % ord(n[i]) + + (' ' if int(x)^parity(ord(n[i])) else '! ') + for i, x in enumerate(("{0:08b}".format(ord(p)))) + ] + print ''.join(nonce_string[:4]) + print ''.join(nonce_string[4:]) diff --git a/txttobin.py b/txttobin.py new file mode 100644 index 0000000..670e9ed --- /dev/null +++ b/txttobin.py @@ -0,0 +1,28 @@ +import sys +data = file(sys.argv[1], 'rb').readlines() +uid = sys.argv[1].replace('.txt','') + +def parity(x): + return ("{0:08b}".format(x).count('1') & 1) + +uid=raw_input("uid> ") +fp = file(uid+'_generated.bin','wb') +fp.write(uid.decode('hex')+"\x00"*2) +bits = 0 +pbits = 0 +for l in data: + if bits == 8: + fp.write(chr(pbits)) + bits = 0 + pbits = 0 + hexbytes = filter(None, l.strip().split(' ')) + bits += 4 + for x in hexbytes: + b = int(x.replace('!', ''), 16) + p = parity(b) + if '!' not in x: + p^=1 + pbits <<= 1 + pbits |= p + fp.write(chr(b)) +