C-001.AFOed-zjy111-and-shenbear.easy_pvz.20210827.4ed6612d.7z

This script is used for downloading and decrypting a file from a specific location on the internet using advanced encryption methods. The script starts by importing various modules including those for handling file paths, encryption, and internet requests. The script then defines a few variables, including a filename and a flag for debugging.

The script then defines a class called "Seed" which contains information such as the key, ar, and checksum required for downloading the file. It also defines a class called "KeyDerivation" which is used to generate keys for the decryption process.

The script then defines a few functions, including one to handle internet requests, one to extract and decrypt the file, and one to decrypt the data using AESGCM encryption method. The script then uses these functions to download and decrypt the file specified in the filename variable.

Finally, if the script is run as the main program and the debug flag is not set, it saves the decrypted file to the current directory using the specified filename. If the debug flag is set, it will output some debug information. The end result is a decrypted file that can be used for further processing or viewing.

import os
from base64 import urlsafe_b64decode
from hashlib import sha3_256, sha3_512
from json import loads

from cryptography.hazmat.primitives.ciphers.aead import AESGCM
from requests.models import Response
from requests.sessions import Session

filename: str = r"C-001.AFOed-zjy111-and-shenbear.easy_pvz.20210827.4ed6612d.7z"
debug: bool = False


class Seed:
    key: bytes = urlsafe_b64decode(
        b"XsAfd6yUqbvygl7c6-TROQr384RNc1pRoLq_NjDTKcFptN7LGVKzzd8Ky8-UJTp6iCZ5TKNylbZ3PTYL3zVXbQ=="
    )
    ar: str = "9wD646AABABh-zlcT0Tl0KnsOC01hW2azljzXBJd6gc"
    checksum: str = "etRAMVObw8eAqKxQYVx23HIIC2L5Ggi-xhieUHYenXA="


class KeyDerivation:
    def __init__(self, iv: bytes, next: bytes) -> None:
        assert len(iv) == 256, "iv must be 2048 bits"
        assert len(next) == 64, "next must be 512 bits"
        self.__generator__ = sha3_512(iv)
        self.__next__ = next

    def __call__(self) -> bytes:
        self.__generator__.update(self.__generator__.digest())
        self.__generator__.update(self.__next__)
        return self.__generator__.digest()


def decrypt(data: bytes, key: bytes) -> bytes:
    assert len(key) == 64, "key must be 512 bits"
    return AESGCM(key=key[:32]).decrypt(
        nonce=key[-12:], data=data, associated_data=key[32:-12]
    )


session = Session()


def get(ar: str) -> Response:
    print("ar", ar)
    while True:
        try:
            resp = session.get(f"https://arweave.net/{ar}/d")
            resp.raise_for_status()
            return resp
        except Exception as err:
            print("error", err)


def extract(key: bytes, ar: str, checksum: str) -> bytes:
    checksum = urlsafe_b64decode(checksum)
    checked = False
    while not checked:
        data = get(ar).content[12:]
        checked = checksum == (sha3_256(data).digest())
    return decrypt(data=data, key=key)


if __name__ == "__main__":
    seed = loads(extract(key=Seed.key, ar=Seed.ar, checksum=Seed.checksum))
    keyDerivation = KeyDerivation(
        iv=urlsafe_b64decode(seed["crypto"]["iv"]),
        next=urlsafe_b64decode(seed["crypto"]["next"]),
    )

    print("debug", debug)
    if debug:
        for obj in seed["store"]:
            key = keyDerivation()
            extract(key=key, ar=obj["ar"], checksum=obj["checksum"])
    else:
        import sys

        if getattr(sys, "frozen", False):
            current = os.path.dirname(sys.executable)
        else:
            current = os.path.dirname(os.path.abspath(__file__))

        with open(os.path.join(current, filename), "wb") as fout:
            for obj in seed["store"]:
                key = keyDerivation()
                fout.write(extract(key=key, ar=obj["ar"], checksum=obj["checksum"]))