好吧,我正在测试我在python中制作的强力算法。唯一的问题是,当它获得我想要的密码而不是打印出来时,密码是正确的:密码'它继续列出其他可能的选项。甚至没有停顿。这是代码:
import itertools
import os
lettersChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
numbersChar = '1234567890'
allChar = 'abcdefghijklmnopqrstuvwxyz_0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'
def CrackPassword(characters):
realPass = input(' What Password Would You Like To Use : ')
amount = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
for i in amount:
gen = itertools.combinations_with_replacement(characters,i)
for password in gen:
convert = ''.join(password)
if(convert == realPass):
print('Password Is Correct : ' + convert)
os.system('pause')
return True
else:
print('Not Correct : ' + convert)
如果有人能帮助我,我将不胜感激:D
答案 0 :(得分:2)
您需要itertools.product(chars, repeat=i)
,因为您需要排列,而不是替换的组合。
您可以在MathIsFun上详细了解排列,组合等之间的区别。