Skip to content

Instantly share code, notes, and snippets.

@vj0shii
Created May 24, 2019 07:45
Show Gist options
  • Save vj0shii/182e94179482cda991024acc03fe1901 to your computer and use it in GitHub Desktop.
Save vj0shii/182e94179482cda991024acc03fe1901 to your computer and use it in GitHub Desktop.
import os, time
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto import Random
from optparse import *
def decrypt(key, filename):
chunksize = 64 * 1024
outputFile = filename.split('en')[1]
with open(filename, 'rb') as infile:
filesize = int(infile.read(16))
IV = infile.read(16)
decryptor = AES.new(key, AES.MODE_CBC, IV)
with open(outputFile, 'wb') as outfile:
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
outfile.write(decryptor.decrypt(chunk))
outfile.truncate(filesize)
def getKey(password):
hasher = SHA256.new(password.encode('utf-8'))
return hasher.digest()
filename = raw_input("Enter filename")
password = raw_input("Enter password")
key = getKey(password)
decrypt(key,filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment