暴力攻击(教育目的)[已关闭]

问题描述 投票:0回答:1

我正在尝试解密并了解暴力攻击的工作原理,尽管我在让程序返回正确的密码时遇到了麻烦。我目前拥有的代码如下

def guess_password(email, target_password):
# Try to guess the password
for i in range(11111, 100000):
    guessed_password = str(i) + "@ecsd"
    print("Guessing password:", guessed_password)

    if guessed_password == target_password:
        print("Password guessed successfully:", guessed_password)
        break

if __name__ == "__main__":
email = input("Enter the email address: ")
target_password = input("Enter the target password: ")
guess_password(email, target_password)

附加说明:在 Python 中运行,适用于 Gmail

python passwords brute-force python-3.12
1个回答
0
投票

缩进很重要。其他解释已按需要给出

def guess_password(email, target_password):
    
    # Try to guess the password
    for i in range(11111, 100000):
    
        # As we use f-string often, have the practice of using f-string
        guessed_password = f'{i}@ecsd'
        print("Guessing password:", guessed_password)

        if guessed_password == target_password:
        
            # when we use return statement, we dont need to use break
            return f"Password guessed successfully: {guessed_password}"
            

if __name__ == "__main__":
    email = input("Enter the email address: ")
    target_password = input("Enter the target password: ")
    r = guess_password(email, target_password)
    print(r)
© www.soinside.com 2019 - 2024. All rights reserved.