From 4962d41420e10c9e05238b97065236d50d7c624d Mon Sep 17 00:00:00 2001 From: "adam@algroup.co.uk" Date: Sat, 5 Sep 2009 07:14:35 +0000 Subject: [PATCH] tool to find correct byte for 8-bit XOR CRC --- tools/xorcheck.py | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100755 tools/xorcheck.py diff --git a/tools/xorcheck.py b/tools/xorcheck.py new file mode 100755 index 00000000..ddfcf82a --- /dev/null +++ b/tools/xorcheck.py @@ -0,0 +1,55 @@ +#!/usr/bin/python + +# xorcheck.py - find xor values for 8-bit CRC +# +# Adam Laurie +# http://rfidiot.org/ +# +# This code is copyright (c) Adam Laurie, 2009, All rights reserved. +# For non-commercial use only, the following terms apply - for all other +# uses, please contact the author: +# +# This code is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This code is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +import sys +import os + +if(len(sys.argv) < 3): + print + print sys.argv[0] + ' - generate final byte for XOR CRC' + print 'Usage: ' + sys.argv[0] + ' ... ' + print + print '\tSpecifying the bytes of a UID with a known CRC will generate the last byte value' + print '\tneeded to generate that CRC with a rolling XOR. All bytes should be specified in HEX.' + print + print 'Example:' + print + print '\txorcheck.py 04 00 80 64 ba' + print + print 'Should produce the output:' + print + print '\tTarget matched with Byte value: 5A' + print + os._exit(True) + +target= int(sys.argv[len(sys.argv) - 1],16) + +for candidate in range(256): + crc= 0x00 + for i in range(len(sys.argv) - 2): + crc ^= int(sys.argv[i + 1],16) + crc ^= candidate + if (crc == target): + print + print 'Target matched with Byte value: %02X' % candidate + print + -- 2.39.2