X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/79c4de2a0f32604f0ae6a4e4845bdac8f44b6e81..30a5d3552930ab77d489484fcd47f296b69dfe34:/tools/findbits.py?ds=sidebyside diff --git a/tools/findbits.py b/tools/findbits.py index 03e0c4e0..1860964b 100755 --- a/tools/findbits.py +++ b/tools/findbits.py @@ -22,23 +22,14 @@ import sys import os -import string # invert binary string def invert(data): - i= 0 - out= '' - while(i < len(data)): - if data[i] == '0': - out += '1' - else: - out += '0' - i += 1 - return out + return ''.join('0' if c == '1' else '1' for c in data) # do the actual search def search(target,data): - location= string.find(data,target) + location = data.find(target) if location >= 0: print '*** Match at bit %d:' % location, print '%s<%s>%s' % (data[:location],target,data[location+len(target):]) @@ -47,21 +38,14 @@ def search(target,data): # convert integer to binary string def binstring(number): - out= '' - while number > 0: - out += chr(0x30 + (number & 0x01)) - number= number >> 1 - return stringreverse(out) + return bin(number)[2:] if number > 0 else '' # reverse string order def stringreverse(data): - out= '' - for x in range(len(data) -1,-1,-1): - out += data[x] - return out + return data[::-1] # match forward, backward and inverted -def domatch(number,binary): +def domatch(binary,number): reversed= stringreverse(number) inverted= invert(binary) @@ -100,11 +84,11 @@ def main(): 16:'HEX', } - for base in 2,8,10,16: + for base, base_name in sorted(bases.iteritems()): try: number= int(sys.argv[1],base) print - print 'Trying', bases[base] + print 'Trying', base_name # do BINARY as specified to preserve leading zeros if base == 2: domatch(sys.argv[1],sys.argv[2])