我正在尝试解密并了解暴力攻击的工作原理,尽管我在让程序返回正确的密码时遇到了麻烦。我目前拥有的代码如下
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
缩进很重要。其他解释已按需要给出
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)