Skip to content

Instantly share code, notes, and snippets.

@ForceTower
Last active August 3, 2020 18:49

Revisions

  1. ForceTower renamed this gist Aug 3, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. ForceTower created this gist Aug 3, 2020.
    26 changes: 26 additions & 0 deletions main.py
    Original 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')