Python. Криптография

Подскажите пожалуйста где ошибся или неправильно написал код. Код работает, но 5-е чувство подсказывает что он неправильный.
Буду очень признателен за любую помощь.
Если возможно, был бы рад коду с комментариями. P.S.
Условие задачи:
Реализуйте атакующую грубую нагрузку на текст, зашифрованный AES.
В качестве возможности получения трехзначного числа.

Код:

    from Crypto.Cipher import AES
    from Crypto import Random
    import hashlib
    import random
    
    BS = AES.block_size
    pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
    
    plain_text = """We are Anonymous.
    We are Legion.
    We do not forgive.
    We do not forget.
    Expect us.
    """
    key = hashlib.sha256(b"357").digest()
    print("Key:", key)
    plain_text = pad(plain_text)
    iv = Random.new().read(BS)
    cipher = AES.new(key, AES.MODE_CBC, iv)
    cipher_text = (iv + cipher.encrypt(plain_text.encode()))
    print("\nCiphered text:", cipher_text)
    correctPassword = "357"
    wrongPasswords = []
    password = ""
    length = 3
    chars = "1234567890"
    run = True
    while run:
    password = ""
    for i in range(length):
    password += random.choice(chars)
    if password not in wrongPasswords:
    if password != correctPassword:
    print(password)
    wrongPasswords.append(password)
    else:
    run = False
    break
    print(password + "is correct")
    unpad = lambda s : s[:-ord(s[len(s)-1:])]
    cipher_text = cipher_text
    iv = cipher_text[:BS]
    cipher = AES.new(key, AES.MODE_CBC, iv)
    plain_text = unpad(cipher.decrypt(cipher_text[BS:]))
    print("\nPlain text:", plain_text)

Ответы (0 шт):