kvib

National Trust Collections image downloader-decrypter

Mar 23rd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. #! /usr/local/bin/python3
  2.  
  3. # National Trust Collections zoomable image downloader-decrypter
  4.  
  5. # -input parameters-
  6. # URL of the image page with zoomable content
  7. url = "http://www.nationaltrustcollections.org.uk/object/593156"
  8. # Name/path of the file that will be saved to disk
  9. output_filename = "decrypted.jpg"
  10.  
  11. ########################
  12.  
  13. from urllib.request import urlopen
  14. import re
  15.  
  16. #       RC4, ARC4, ARCFOUR algorithm
  17. #
  18. #       Copyright (c) 2009 joonis new media
  19. #       Author: Thimo Kraemer <thimo.kraemer@joonis.de>
  20. #       License: GPL
  21. def rc4crypt(data, key):
  22.     x = 0
  23.     box = list(range(256))
  24.     for i in range(256):
  25.         x = (x + box[i] + ord(key[i % len(key)])) % 256
  26.         box[i], box[x] = box[x], box[i]
  27.     x = 0
  28.     y = 0
  29.     out = bytearray()
  30.     for char in data:
  31.         x = (x + 1) % 256
  32.         y = (y + box[x]) % 256
  33.         box[x], box[y] = box[y], box[x]
  34.         out.append(char ^ box[(box[x] + box[y]) % 256])
  35.     return out
  36.  
  37. fileurl = "http://www.nationaltrustcollections.org.uk"
  38. with urlopen(url) as imgpage:
  39.     fileurl += re.search(r"/EncryptedZoomImage\.ashx\?id_fichier=\d+", imgpage.read().decode()).group(0)
  40.  
  41. key = "asdas98as9dasdhas9yd9a8sd8uasu0asdu0uas0asdasd979asyyua98sdyhd08a0889daysdt6cf8dagbcsdahc9gs8ydgb"
  42. with urlopen(fileurl) as inf, open(output_filename, 'wb') as outf:
  43.     outf.write(rc4crypt(inf.read(), key))
Add Comment
Please, Sign In to add comment