不同长度列表的组合生成器,嵌套for循环,而不是intertool

2024-07-02 10:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试图在python中获得嵌套for循环的句柄,所以我制作了一个组合生成器,循环直到找到字母、数字和特殊字符的正确组合。我知道intertools是最简单的方法,但是我需要更好地理解嵌套for循环是如何工作的。下面是我希望代码如何工作。你知道吗

a

b类

c级

。。。你知道吗

1个

。。。你知道吗

~

@

#

。。。你知道吗

A

B类

C级

。。。你知道吗

aa级

ab型

交流

以此类推。你知道吗

它继续浏览我的列表,直到找到正确的字符集。到它结束时,会有相当多的迭代。你知道吗

这是我的密码

# this program is a password cracker that uses loops to find an appropriate character.
# It is capable of using numbers, letters, basic symbols, capitol letters, and up to 8 characters.
# It checks the whole list at once against the other whole list


lowalpha = ['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']
upalpha = ['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']
special = ['!', '@', '#', '$', '%', '^', '&', '*', '~', '?']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
hiddenpass = ['D', 'r', 'i', 'n', 'k', 'c', 'o', 'f', 'f', 'e', 'e']

i = len(hiddenpass)
password = ['']*i

low = 0
up = 0
sp = 0
num = 0
X = 0
Y = 0
Z = 1


   def iterator():
        global low, up, sp, num, X, password, lowalpha, upalpha, special, numbers
        for low in range(len(lowalpha)):
            password[X] = lowalpha[low]
        for up in range(len(upalpha)):
            password[X] = upalpha[up]
        for sp in range(len(special)):
            password[X] = special[sp]
        for num in range(len(numbers)):
            password[X] = numbers[num]


if password != hiddenpass:
    for Y in range(len(password)):
        for Z in range(len(lowalpha)):
            password[Y] = lowalpha[Z]
            iterator()
            X = X + 1
        low = 0
        up = 0
        sp = 0
        num = 0
        X = 0
        Y = 0
        Z = 1
        for Z in range(len(upalpha)):
            password[Y] = upalpha[Z]
            iterator()
            X = X + 1
        low = 0
        up = 0
        sp = 0
        num = 0
        X = 0
        Y = 0
        Z = 1
        for Z in range(len(special)):
            password[Y] = special[Z]
            iterator()
            X = X + 1
        low = 0
        up = 0
        sp = 0
        num = 0
        X = 0
        Y = 0
        Z = 1
        for Z in range(len(numbers)):
            password[Y] = numbers[Z]
            iterator()
            X = X + 1
else:
    print('got em')

到目前为止,这不起作用,并且在第一次调用iterator()时失败。它在该函数中的password[X] = lowalpha[low]处失败。https://imgur.com/a/4NZli这是错误代码。你知道吗


Tags: inforlenrangepasswordnumsplow
1条回答
网友
1楼 · 发布于 2024-07-02 10:27:07

由于我的处理器发热问题,我无法对所有组合进行测试,但我可以告诉您您需要什么:

import sys

lowalpha = ['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']
upalpha = ['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']

def repeat(*args, repeat=3):
    result_1 = [tuple(i) for i in args] * repeat



    final_list=[[]]

    for i in result_1:
        copy_final=final_list

        final_list=[]

        for j in copy_final:

            for k in i:
                find=([k]+j)
                if find==['a','n','k']:
                    print("Here is find",find)
                    sys.exit()



                final_list.append(find)






repeat(lowalpha,lowalpha)

相关问题 更多 >