Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 强力发生器不';不知道什么时候猜到了密码_Python_Algorithm_Python 3.x_Brute Force - Fatal编程技术网

Python 强力发生器不';不知道什么时候猜到了密码

Python 强力发生器不';不知道什么时候猜到了密码,python,algorithm,python-3.x,brute-force,Python,Algorithm,Python 3.x,Brute Force,好的,我正在测试我用python制作的蛮力算法。唯一的问题是当它得到我想要的密码时,而不是打印出“password is Correct:password”,它继续列出其他可能的选项。甚至没有停顿。代码如下: import itertools import os lettersChar = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' numbersChar = '1234567890' allChar = 'abcdefghij

好的,我正在测试我用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)
,因为您需要的是置换,而不是替换组合


你可以阅读更多关于排列、组合等之间差异的信息。

显示你调用的部分
CrackPassword
这对我来说使用
CrackPassword(numbersChar)
很好,因为你使用的是带有替换的
组合,每个生成的密码都是按顺序排序的。因此,如果您的输入类似于321,则生成的密码都不会与您的输入匹配。看起来你想要“置换置换”,虽然没有一种简单的方法可以做到这一点,比如用
置换组合
@Greg:“置换置换置换”是
itertools.product