Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import argparse
- def convert(f):
- """ Converts a mifare text file into an array of bytes. """
- output = []
- # iterate each line in the file
- for line in f:
- # if the line begins with +, it is marking the sector so ignore
- if line.startswith('+'):
- continue
- # iterate each 2 chars in the line
- for i in range(0, len(line)-1, 2):
- # read the next two chars and convert from hex
- output.append(int(line[i:i+2], base=16))
- return bytes(output)
- def main():
- parser = argparse.ArgumentParser(
- description='Convert a MiFare Text dump to a binary dump')
- parser.add_argument('input', help='Input file', type=str)
- parser.add_argument('output', help='Output file', type=str)
- args = parser.parse_args()
- infile, outfile = args['input'], args['output']
- # open input file and output file
- with open(infile, 'r') as fin, open(outfile, 'wb') as fout:
- # write converted bytes from fin to fout
- fout.write(convert(fin))
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement