Advertisement
Guest User

decode-A858

a guest
Dec 14th, 2015
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. #/bin/python
  2.  
  3. import os
  4. import binascii
  5. from Crypto.Cipher import DES
  6. key = "A858DE45"
  7. decypt = False
  8.  
  9. # https://pythonhosted.org/pycrypto/Crypto.Cipher.DES3-module.html
  10. # MODE_EBC == Electronic Code Book == 1
  11. cipher = DES.new(key, 1)
  12.  
  13.  
  14. for fileStr in os.listdir("./posts"):
  15.     f = open("./posts/"+fileStr)
  16.     if fileStr == "allPosts":
  17.         continue
  18.     lines = f.readlines()
  19.     content = lines[-2]
  20.     content = content[:-2]
  21.     decoded = ''
  22.     i = 0
  23.  
  24.     # Decoding the text...
  25.     if decypt:
  26.         msg = cipher.encrypt(content.replace(" ", ""))
  27.         content = msg.decode(encoding='UTF-8', errors='ignore')
  28.    
  29.  
  30.     # Getting the ASCII out of hex
  31.     while i < len(content):
  32.         if content[i] == ' ':
  33.             i += 1
  34.             continue
  35.  
  36.         try:
  37.             if int(content[i:i+2], 16) < 128:
  38.                 decoded += chr(int(content[i:i+2], 16))
  39.             else:
  40.                 print("ERROR, not a ascii text file")
  41.                 break
  42.         except(ValueError):
  43.             print(fileStr)
  44.             break
  45.  
  46.         i += 2
  47.     if i == len(content):
  48.         # it got all the way through...
  49.         print(decoded)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement