From aa6fc60a22f3b5cbfd0a0aa4255138c14ff07faa Mon Sep 17 00:00:00 2001 From: Philippe Teuwen Date: Fri, 21 Feb 2020 16:29:52 +0100 Subject: [PATCH] xorcheck script converted in python3 + test --- pm3test.sh | 1 + tools/xorcheck.py | 37 +++++++++++++++++-------------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/pm3test.sh b/pm3test.sh index 146650f71..7a623183c 100755 --- a/pm3test.sh +++ b/pm3test.sh @@ -116,6 +116,7 @@ while true; do if ! CheckExecute "mfkey64 test" "tools/mfkey/mfkey64 9c599b32 82a4166c a1e458ce 6eea41e0 5cadf439" "Found Key: \[ffffffffffff\]"; then break; fi if ! CheckExecute "mfkey64 long trace test" "tools/mfkey/./mfkey64 14579f69 ce844261 f8049ccb 0525c84f 9431cc40 7093df99 9972428ce2e8523f456b99c831e769dced09 8ca6827b ab797fd369e8b93a86776b40dae3ef686efd c3c381ba 49e2c9def4868d1777670e584c27230286f4 fbdcd7c1 4abd964b07d3563aa066ed0a2eac7f6312bf 9f9149ea" "Found Key: \[091e639cb715\]"; then break; fi if ! CheckExecute "nonce2key test" "tools/nonce2key/nonce2key e9cadd9c a8bf4a12 a020a8285858b090 050f010607060e07 5693be6c00000000" "key recovered: fc00018778f7"; then break; fi + if ! CheckExecute "xorcheck test" "tools/xorcheck.py 04 00 80 64 ba" "final LRC XOR byte value: 5A"; then break; fi printf "\n${C_GREEN}Tests [OK]${C_NC}\n\n" exit 0 done diff --git a/tools/xorcheck.py b/tools/xorcheck.py index 04c031cf1..205e41ccb 100755 --- a/tools/xorcheck.py +++ b/tools/xorcheck.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python +#!/usr/bin/env python3 # xorcheck.py - find xor values for 8-bit LRC # @@ -24,22 +24,21 @@ import sys import os if(len(sys.argv) < 3): - print - print '\t'+sys.argv[0] + ' - Generate final byte for XOR LRC' - print - print 'Usage: ' + sys.argv[0] + ' ... ' - print - print '\tSpecifying the bytes of a UID with a known LRC will find the last byte value' - print '\tneeded to generate that LRC 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 (BA) requires final LRC XOR byte value: 5A' - print + print(""" +\t{0} - Generate final byte for XOR LRC + +Usage: {0} ... + +\tSpecifying the bytes of a UID with a known LRC will find the last byte value +\tneeded to generate that LRC with a rolling XOR. All bytes should be specified in HEX. + +Example: + +\t{0} 04 00 80 64 ba + +Should produce the output: + +\tTarget (BA) requires final LRC XOR byte value: 5A\n""".format(sys.argv[0])) os._exit(True) target= int(sys.argv[len(sys.argv) - 1],16) @@ -47,6 +46,4 @@ target= int(sys.argv[len(sys.argv) - 1],16) lrc= 0x00 for i in range(len(sys.argv) - 1): lrc ^= int(sys.argv[i + 1],16) -print -print 'Target (%02X) requires final LRC XOR byte value: %02X' % (target,lrc) -print +print('\nTarget (%02X) requires final LRC XOR byte value: %02X\n' % (target,lrc))