agentirons

pfcoder

Sep 29th, 2016
110
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. from struct import *
  3.  
  4. def read_as_byte(filename):
  5.     handle = open(filename, 'rb')
  6.     fsize = os.path.getsize(filename)
  7.     contents = handle.read(fsize)
  8.     byteArray = unpack(str(fsize)+'B',contents)
  9.     return byteArray
  10.    
  11. def savefile(data, filename):
  12.     string = ''
  13.     for byte in data:
  14.         string = string+chr(byte)
  15.     fp = open(filename, 'w')
  16.     fp.write(string)
  17.     fp.close()
  18.  
  19. dec_key = read_as_byte('./canon_ps.key')
  20. enc_file = read_as_byte('./PictureStyle.pf2')
  21.  
  22. i = -11
  23. dec = []
  24.  
  25. for ef in enc_file:
  26.     if (i > -1):
  27.         dec.append(ef^dec_key[i])
  28.         i = i%(512*513)
  29.     else:
  30.         dec.append(ef)
  31.     i = i+1
  32. savefile(dec, './PictureStyle.decoded.pf2')
RAW Paste Data