我的代码是
from random import *
guess = ""
password = input("Password: ")
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
while (guess != password):
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
我的目标是让它随机生成字母并将它们粘在一起以形成密码的长度,并在找到密码之前执行此操作。每次运行它时,它只会使命令提示符看起来像Matrix中的某些东西。我有什么不对的吗?
P.S。我这样做是为了看看破解密码有多难。我无意侵入其他人的账户。
答案 0 :(得分:2)
你永远不会重置"猜测"所以它不断变得越来越大。
from random import *
guess = ""
password = input("Password: ")
letters = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"]
while (guess != password):
guess = ""
for letter in password:
guessletter = letters[randint(0, 25)]
guess = str(guessletter) + str(guess)
print(guess)
print("Password guessed!")
input("")
答案 1 :(得分:0)
正如已经说过的那样,你没有正确地重新设定猜测。
此外,这不是你如何破解密码,因为你反复重复相同的猜测。你需要以某种方式克服所有可能性,而不是重复自己。
假设您的密码长度为4个字母,您可以从aaaa开始,然后是aaab,直到zzzz。你可以用另一个顺序,一个随机的顺序,但你应该只测试每个案例一次。