SHARE
TWEET

Untitled

a guest May 21st, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import argparse
  2.  
  3.  
  4. def convert(f):
  5.     """ Converts a mifare text file into an array of bytes. """
  6.     output = []
  7.     # iterate each line in the file
  8.     for line in f:
  9.         # if the line begins with +, it is marking the sector so ignore
  10.         if line.startswith('+'):
  11.             continue
  12.         # iterate each 2 chars in the line
  13.         for i in range(0, len(line)-1, 2):
  14.             # read the next two chars and convert from hex
  15.             output.append(int(line[i:i+2], base=16))
  16.  
  17.     return bytes(output)
  18.  
  19.  
  20. def main():
  21.     parser = argparse.ArgumentParser(
  22.         description='Convert a MiFare Text dump to a binary dump')
  23.     parser.add_argument('input', help='Input file', type=str)
  24.     parser.add_argument('output', help='Output file', type=str)
  25.  
  26.     args = parser.parse_args()
  27.     infile, outfile = args['input'], args['output']
  28.  
  29.     # open input file and output file
  30.     with open(infile, 'r') as fin, open(outfile, 'wb') as fout:
  31.         # write converted bytes from fin to fout
  32.         fout.write(convert(fin))
  33.  
  34.  
  35. if __name__ == '__main__':
  36.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top