Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Crypto.Cipher import AES
- from Crypto.Hash import SHA256
- from Crypto import Random
- import os
- import sys
- def getKey(password):
- hasher = SHA256.new(password.encode('utf-8'))
- return hasher.digest()
- def decrypt (key):
- filename = "enim_msg.txt"
- chunksize = 64*1024
- outfile = "en" + filename
- #filesize = str(os.path.getsize(filename)).zfill(16)
- #IV = Random.new().read(16)
- f = open(filename, "r")
- filesize = f.read(16) #Read the first 13 chars
- IV = f.read(16) #Once read filesize read the next 3 chars = IV
- print ("Filesize: "+ str(filesize) + " IV: " + str(IV))
- decryptor = AES.new(key, AES.MODE_CBC, IV)
- outputFile = "finally.txt"
- with open(filename, 'rb') as infile:
- with open(outputFile, 'wb') as outfile:
- #outfile.write(filesize.encode('utf-8'))
- #outfile.write(IV)
- while True:
- chunk = infile.read(chunksize)
- if len(chunk) == 0:
- break
- elif len(chunk) % 16 != 0:
- chunk += b' ' * (16 - (len(chunk) % 16))
- outfile.write(decryptor.decrypt(chunk))
- password = "sahay"
- key = getKey(password)
- decrypt(key)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement