我为我的一个课程制作了一个强力密码破解程序,但无法弄清楚为什么它没有完全检查每个组合。如果我使用只有数字或小写字母的简单密码,它通常可以工作,但复杂的字符组合根本不一定会产生答案。
这是我为我的作业提交的代码:
from datetime import datetime
from itertools import combinations_with_replacement, permutations
#############################
# Password Cracking Program #
#############################
possibleChars = ["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", "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", "0", "1", "2", "3", "4",
"5", "6", "7", "8", "9", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")"]
# Get the current time after program runs, subtracts it from the initial time
now = datetime.now()
password = input("Enter a 4 character password:\n")
combinations = list(combinations_with_replacement(possibleChars, 4)) + list()
totalTries = 0
for combo in combinations:
totalTries += 1
print(join(combo))
if password == "".join(combo):
print("Your password is: " + password)
print(totalTries)
# Output the difference in seconds
later = datetime.now()
diff = (later - now).total_seconds()
print(diff)
break
任何帮助表示赞赏!