import itertools
from hashlib import scrypt
import base64


def calc_hash(password: str, username: str) -> list[bytes]:
    return base64.b64encode(
        scrypt(password.encode(), salt=username.encode(), n=16384, r=4, p=1)
    ).decode()
    # return scrypt(password.encode(), salt=username.encode(), n=16384, r=4, p=1)


def generate_passwords():
    letters = "abcdefghijklmnopqrstuvwxyz"
    with open("rainbow_table.json", "w") as f:
        f.write("{\n")
        for prefix in itertools.product(letters, repeat=3):
            password = "".join(prefix + "123")
            hashed = calc_hash(password, "admin")
            f.write(f'"{password}":"{hashed}",\n')
            print("".join(prefix) + "".join("123"))
        f.write("\n}")


if __name__ == "__main__":
    generate_passwords()
