如何让我的Python密码破解器更高效的运行?

问题描述 投票:0回答:1

不久前,我对制作一个伪密码破解器很感兴趣,所以,这里有一些代码。

list = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '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'] # giving it a list 

passlength = int(input('Length of string: ')) # length of code or no of objects
aspass = '' # empty string acts as assumed password
passs = input('Please input password ') # he infamous password
b = [] # the list that will stores randomly generated passwords as values
attempt = 0
digits = 0   
o = True
while o:
    for k in range(0, passlength): # run this loop as many times as the length of password
        x = str(random.choice(list))#the attempted upon digit in the password
        aspass += x
        digits += 1 # counts the step the cracker is on
        #print(aspass)
        if(len(aspass) > passlength or aspass in b):
            digits = 0
            attempt += 1
            break
        else:
            continue
        #b.append(aspass)
    if(aspass == passs):
        break
        o = False
        end()
    else:
        b.append(aspass)
        aspass = ''
        continue

事情是这样的,一切都正常,它能很好地生成2个字符串的密码。然而,如果长度超过2或3个字符串。那么,它就会以蜗牛的速度移动。然后,我有了一个想法,如果我可以把随机生成的密码保存在我做的 "b "列表中,并确保该列表中的密码不会在这个过程中重复,那么我想它的运行速度会大大加快。

由于我是一个完全的初学者,我不知道如何使它更快任何其他方式。我可以尝试什么东西(例如,可导入的模块)来改善这个问题?

python python-3.x passwords
1个回答
1
投票

密码破解不是一件容易的工作。想一想,随着密码长度的增加,你必须要经历的搜索空间。你的可能字符列表包含26个字母和10个数字(顺便说一下,你可以使用 string.digitsstring.ascii_lowercase). 因此,对于密码中的第一个字符,有36个选项。第二个有36个选项,第三个有36个选项,以此类推。因此,对于一个长度为 n 你将有3^n个选项。正如你很快就能看到的那样,即使是小数,这个数字也在极速增长。

你破解密码的方法叫做 蛮力攻击 而且效率极低,特别是考虑到大多数密码不是以纯文本而是以哈希字符串的形式存储。

其他一些注意事项。

  1. 你的变量名称不是很好 他们中的大多数都是毫无意义的,这让你的代码更难理解。
  2. 你选择了随机的字符串,而不是按顺序通过所有可能的选项。你没有办法用这种方法覆盖所有的选项。你可以使用 itertools.permutations 用于遍历所有选项。
  3. 不要在 if 语句,这不是Python的方式。求你了。
© www.soinside.com 2019 - 2024. All rights reserved.