Last active
August 3, 2020 18:49
Revisions
-
ForceTower renamed this gist
Aug 3, 2020 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
ForceTower created this gist
Aug 3, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ from Crypto.Cipher import AES from Crypto.Util import Counter def encrypt_file(key, in_filename, out_filename=None, chunksize=64 * 1024): if not out_filename: out_filename = in_filename + '.enc' counter = Counter.new(nbits=128, initial_value=0) encryptor = AES.new(key, AES.MODE_CTR, counter=counter) with open(in_filename, 'rb') as infile: with open(out_filename, 'wb') as outfile: while True: chunk = infile.read(chunksize) if len(chunk) == 0: break elif len(chunk) % 16 != 0: chunk += ' ' * (16 - len(chunk) % 16) enc = encryptor.encrypt(chunk) outfile.write(enc) if __name__ == '__main__': encrypt_file(bytes('a_really_strong_password', 'utf8'), 'd.mp4')