daily pastebin goal
57%
SHARE
TWEET

Untitled

a guest Mar 24th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from Crypto.Cipher import AES
  2. from Crypto.Hash import SHA256
  3. from Crypto import Random
  4. import os
  5. import sys
  6.  
  7. def getKey(password):
  8.             hasher = SHA256.new(password.encode('utf-8'))
  9.             return hasher.digest()
  10.  
  11.  
  12. def decrypt (key):
  13.     filename = "enim_msg.txt"
  14.     chunksize = 64*1024
  15.     outfile = "en" + filename
  16.     #filesize = str(os.path.getsize(filename)).zfill(16)
  17.     #IV = Random.new().read(16)
  18.     f = open(filename, "r")
  19.     filesize = f.read(16) #Read the first 13 chars
  20.     IV = f.read(16) #Once read filesize read the next 3 chars = IV
  21.     print ("Filesize: "+ str(filesize) + " IV: " + str(IV))
  22.  
  23.     decryptor = AES.new(key, AES.MODE_CBC, IV)
  24.     outputFile = "finally.txt"
  25.  
  26.     with open(filename, 'rb') as infile:
  27.         with open(outputFile, 'wb') as outfile:
  28.             #outfile.write(filesize.encode('utf-8'))
  29.             #outfile.write(IV)
  30.             while True:
  31.                 chunk = infile.read(chunksize)
  32.  
  33.                 if len(chunk) == 0:
  34.                     break
  35.                 elif len(chunk) % 16 != 0:
  36.                     chunk += b' ' * (16 - (len(chunk) % 16))
  37.  
  38.                 outfile.write(decryptor.decrypt(chunk))
  39. password = "sahay"
  40. key = getKey(password)
  41. decrypt(key)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top