蛮力生成器不会告诉密码何时被猜到

Brute Force Generator Doesn't Tell When Password Was Guessed

好吧,我正在测试我在 python 中制作的强力算法。唯一的问题是当它得到我想要它得到的密码而不是打印出 'Password Is Correct : Password' 它继续列出其他可能的选项。甚至没有停顿。这是代码:

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

您需要 itertools.product(chars, repeat=i),因为您需要排列,而不是替换组合。

您可以在 MathIsFun.

上阅读更多关于排列、组合等之间的区别的信息