Guest User

Untitled

a guest
Mar 17th, 2016
918
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python3
  2.  
  3. # good file is the same file from backups
  4. good_file = "DSC05334.JPG.original"
  5. bad_file = "DSC05334.JPG.crypted"
  6.  
  7. key = []
  8.  
  9. gf = open(good_file, "rb")
  10. bf = open(bad_file, "rb")
  11.  
  12. i = 0
  13. good_byte = gf.read(1)
  14. bad_byte = bf.read(1)
  15.  
  16. print("byte# good bad key")
  17. while i < 600:
  18. key.append(ord(good_byte) ^ ord(bad_byte))
  19. print(str(i) + " " + hex(ord(good_byte)) + " " + hex(ord(bad_byte)) + " " + hex(key[i]))
  20. bad_byte = bf.read(1)
  21. good_byte = gf.read(1)
  22. i = i+1
  23.  
  24. i = 0
  25. print("KEY: ")
  26. print('key = (', end="")
  27. while i < 255:
  28. if key[i] == key[i+255]:
  29. print(hex(key[i]) + ", ", end="")
  30. else:
  31. print("Failed to find decryption key!")
  32. sys.exit(1)
  33. i = i + 1
  34. print(')')
  35. print()
  36. gf.close()
  37. bf.close()
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45. #!/usr/bin/python3
  46.  
  47. from pprint import pprint
  48.  
  49. key = # passte key recovered from the previous snippet
  50.  
  51. bad_file = "DSC05334.JPG.crypted"
  52. new_file = "DSC05334.JPG.new"
  53.  
  54. bf = open(bad_file, "rb")
  55. nf = open(new_file, "wb")
  56.  
  57. i = 0
  58. print("byte# bad key new str(new)")
  59. read_bytes = 0
  60. while read_bytes < 2048:
  61. bad_byte = bf.read(1)
  62. new_byte = (key[i] ^ ord(bad_byte))
  63. print(str(read_bytes) + " " + hex(ord(bad_byte)) + " " + hex(key[i]) + " " + hex(new_byte) + " " + str(new_byte) + " ")
  64. nf.write(bytes([new_byte]))
  65. i = i + 1
  66. if i > 254:
  67. i = 0
  68. read_bytes = read_bytes + 1
  69.  
  70. while bad_byte:
  71. bad_byte = bf.read(1)
  72. nf.write(bad_byte)
  73.  
  74. nf.close()
  75. bf.close()
RAW Paste Data