1
0

sercomm-crypto.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #!/usr/bin/env python3
  2. import argparse
  3. import binascii
  4. import hashlib
  5. import os
  6. import struct
  7. def create_header(key, version, iv, random, size):
  8. header = struct.pack('32s32s32s32s32s', key, version, iv, random, size)
  9. return header
  10. def create_output(args):
  11. in_st = os.stat(args.input_file)
  12. in_size = in_st.st_size
  13. key = "".encode('ascii')
  14. version = args.version.encode('ascii')
  15. iv = "".encode('ascii')
  16. random = "".encode('ascii')
  17. size = str(in_size).encode('ascii')
  18. header = create_header(key, version, iv, random, size)
  19. out_f = open(args.output_file, 'w+b')
  20. out_f.write(header)
  21. out_f.close()
  22. md5 = hashlib.md5()
  23. md5.update(header[0x60:0x80])
  24. md5.update(header[0x20:0x40])
  25. md5_1 = md5.digest()
  26. md5 = hashlib.md5()
  27. md5.update(header[0x80:0xA0])
  28. md5.update(header[0x20:0x40])
  29. md5_2 = md5.digest()
  30. key = md5_1 + md5_2
  31. key_f = open(args.key_file, 'w+b')
  32. key_f.write(binascii.hexlify(bytearray(key)))
  33. key_f.close()
  34. print("AES 256 CBC Key:", binascii.hexlify(bytearray(key)))
  35. def main():
  36. global args
  37. parser = argparse.ArgumentParser(description='')
  38. parser.add_argument('--input-file',
  39. dest='input_file',
  40. action='store',
  41. type=str,
  42. help='Input file')
  43. parser.add_argument('--key-file',
  44. dest='key_file',
  45. action='store',
  46. type=str,
  47. help='AES 256 CBC Key File')
  48. parser.add_argument('--output-file',
  49. dest='output_file',
  50. action='store',
  51. type=str,
  52. help='Output file')
  53. parser.add_argument('--version',
  54. dest='version',
  55. action='store',
  56. type=str,
  57. help='Version')
  58. args = parser.parse_args()
  59. if ((not args.input_file) or
  60. (not args.key_file) or
  61. (not args.output_file) or
  62. (not args.version)):
  63. parser.print_help()
  64. create_output(args)
  65. main()