<jupyter_start><jupyter_text>Decryption Requires access to the "locked" files, and to the corresponding key.<jupyter_code>!dir
# So, we have our Download.CSV.locked, and Download.CSV.key
#!pip install pycryptodome for below:

from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
from Crypto.Util.Padding import pad, unpad

class AESCipher:
    def __init__(self, key):
        self.key = bytes(key)
        self.iv = bytes([47, 28, 226, 107, 181, 219, 38, 58, 118, 181, 139, 61, 227, 13, 96, 202])

    def encrypt(self, data):
        self.cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        return b64encode(self.iv + self.cipher.encrypt(pad(data.encode('utf-8'), 
            AES.block_size)))

    def decrypt(self, data):
        raw = b64decode(data)
        print(type(raw), raw)
        self.cipher = AES.new(self.key, AES.MODE_CBC, raw[:AES.block_size])
        return unpad(self.cipher.decrypt(raw[AES.block_size:]), AES.block_size)

    def decrypt_raw(self, raw):
        self.cipher = AES.new(self.key, AES.MODE_CBC, self.iv)
        return unpad(self.cipher.decrypt(raw), AES.block_size)

def decrypt(fn):
    # assuming that fn.key (key file) is in the same folder as this script:
    with open(fn + '.key', 'r') as f:
        key = list(map(int, f.readline().split(',')))

    # assuming that fn.locked (locked file) is in the same folder as this script:
    with open(fn + '.locked', 'rb') as f:
        encryptedContent = f.read()
        aes = AESCipher(key)
        orig = aes.decrypt_raw(encryptedContent)
        # and writing to the same folder, too:
        with open(fn, 'wb') as wf:
            wf.write(orig)
    

decrypt('Download.CSV')
decrypt('Download.zip')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1329512893982808, 'fraction_numerical': 0.026361031518624643, 'mean_word_length': 3.108235294117647, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '259778', 'license': 'MIT', 'n_tokens_mistral': 668, 'n_tokens_neox': 592, 'n_words': 160, 'path': 'Decrypt.ipynb', 'repo_name': 'likhtal/Encryption-Schemas-with-Zip-Manipulation', 'size': '1745'}