密码破解程序



我正在制作一个密码强度测试程序,该程序将根据花费的时间以及尝试破解密码的次数进行评级。

我希望以最简单的方式之一破解输入,从一个元素开始,[a]一直到[z],然后添加第二个元素,之后,将第一个元素设置回[a],新元素将经过[a]-[z],第二个元素将为第一个元素变成的每个字母重复此操作。 为每个完整旋转添加一个新元素的所有其他元素。直到找到正确的密码。

我的问题是我找不到一种方法从[a]-[z]开始,然后转到[a], [a]-[z]; [b], [a]-[z];等。同时堆叠永远,直到找到正确的密码。我知道这是一种极其无效的方法,但我现在只是在尝试基础知识。

这是我的尝试。我尝试了其他一些方法,但空手而归,所以我求助于在这里发布它。

usrPassword = str(input('')) 
while ''.join(passCheck) != usrPassword :
for passwordLength in range(0, 10) : # this loop would be meant to go on forever.
passCheck.append(' ')
for i in range(0, passwordLength) :
if ''.join(passCheck) != usrPassword :
for j in range(32, 127) :
passCheck[i] = chr(j)
print(passCheck)

这可能不是您要求的逻辑,但我认为它更有效,因为它一次破解一个字母:

import string
usrPassword = list(input('input password: ')) # List of characters
passCheck = ['a'] * len(usrPassword) # Randomly initialize to some string of same length
print("Start cracking the password: {}".format(passCheck))
allowed_chars = list(string.printable) # All printable characters
while ''.join(passCheck) != ''.join(usrPassword):
for ind in range(len(usrPassword)):
match_char = [char for char in allowed_chars if char == usrPassword[ind]][0]
passCheck[ind] = match_char
print("Attempt {}/{}: {}".format(ind+1, len(usrPassword), passCheck))
print("User input: {} nMatched password: {}".format(''.join(usrPassword), ''.join(passCheck)))

目前,这适用于所有可打印字符。

示例输出:

input password: PasswORD-/!=12345
Start cracking the password: ['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 1/17: ['P', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 2/17: ['P', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 3/17: ['P', 'a', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 4/17: ['P', 'a', 's', 's', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 5/17: ['P', 'a', 's', 's', 'w', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 6/17: ['P', 'a', 's', 's', 'w', 'O', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 7/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 8/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 9/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', 'a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 10/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 11/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', 'a', 'a', 'a', 'a', 'a', 'a']
Attempt 12/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', 'a', 'a', 'a', 'a', 'a']
Attempt 13/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', '1', 'a', 'a', 'a', 'a']
Attempt 14/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', '1', '2', 'a', 'a', 'a']
Attempt 15/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', '1', '2', '3', 'a', 'a']
Attempt 16/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', '1', '2', '3', '4', 'a']
Attempt 17/17: ['P', 'a', 's', 's', 'w', 'O', 'R', 'D', '-', '/', '!', '=', '1', '2', '3', '4', '5']
User input: PasswORD-/!=12345 
Matched password: PasswORD-/!=12345

如果您有任何问题,请告诉我。

编辑:

如果您不想使用输入密码的长度:

import string
usrPassword = list(input('input password: ')) # List of characters
passCheck = []
print("Start cracking the password: {}".format(passCheck))
allowed_chars = list(string.printable) # All printable characters
while ''.join(passCheck) != ''.join(usrPassword):
for ind in range(len(usrPassword)):
match_char = [char for char in allowed_chars if char == usrPassword[ind]][0]
passCheck.append(match_char)
print("Attempt {}/{}: {}".format(ind+1, len(usrPassword), passCheck))
print("User input: {} nMatched password: {}".format(''.join(usrPassword), ''.join(passCheck)))

这将产生与上述相同的输出,但附加到 passCheck 而不是使用预分配。

示例输出:

input password: PassworD-/!=12345
Start cracking the password: []
Attempt 1/17: ['P']
Attempt 2/17: ['P', 'a']
Attempt 3/17: ['P', 'a', 's']
Attempt 4/17: ['P', 'a', 's', 's']
Attempt 5/17: ['P', 'a', 's', 's', 'w']
Attempt 6/17: ['P', 'a', 's', 's', 'w', 'o']
Attempt 7/17: ['P', 'a', 's', 's', 'w', 'o', 'r']
Attempt 8/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D']
Attempt 9/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-']
Attempt 10/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/']
Attempt 11/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!']
Attempt 12/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=']
Attempt 13/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=', '1']
Attempt 14/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=', '1', '2']
Attempt 15/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=', '1', '2', '3']
Attempt 16/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=', '1', '2', '3', '4']
Attempt 17/17: ['P', 'a', 's', 's', 'w', 'o', 'r', 'D', '-', '/', '!', '=', '1', '2', '3', '4', '5']
User input: PassworD-/!=12345 
Matched password: PassworD-/!=12345

最新更新