不久前,我对制作一个伪密码破解程序感兴趣。 下面是一些代码:
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”列表中,并确保该列表中的密码在这个过程中不会重复,那么我认为它会运行得更快
由于我是一个完全的初学者,我不知道如何以其他方式使它更快。我可以尝试哪些方法(例如可导入的模块)来改进这一点
破解密码并非易事。考虑一下随着密码长度的增长,您必须通过的搜索空间。您的可能字符列表包含26个字母和10个数字(顺便说一下,您可以使用
string.digits
和string.ascii_lowercase
)。因此,对于密码中的第一个字符,有36个选项。第二个有36个选项,第三个有36个选项,依此类推。因此,对于长度为n
的密码,您将有3^n个选项。正如你很快就能看到的,这个数字正在以极快的速度增长,即使是小数字破解密码的方法称为Brute-force attack,效率极低,特别是考虑到大多数密码不是以明文形式存储的,而是以散列字符串形式存储的
其他注释很少:
if
语句中使用括号,这不是Python的方式。求你了李>我做了一个程序,我想做GUI,但如果你需要它,你可以从命令lilne使用它
这个怎么样:
相关问题 更多 >
编程相关推荐