我使用 python3 创建了一个蛮力程序,在此过程中我总是得到一个 MemoryError。一开始用户必须输入一个哈希算法(所有可能的算法都给出),然后用户必须选择一个字符模式并给出最小和最大可能的密码长度。然后代码使用选择的字符模式并尝试任何可能的组合,使用选择的算法对其进行散列,并将散列与用户的给定散列进行比较。如果它们相等,则代码给出使用该模式组合的密码。问题是,我的代码在密码长度为 5 处执行时崩溃。
错误代码:
Traceback (most recent call last):
File "C:/Users/ashka/PycharmProjects/bruteforce/main.py", line 122, in <module>
main()
File "C:/Users/ashka/PycharmProjects/bruteforce/main.py", line 116, in main
bruteforce(min, max, hash, hashfunction)
File "C:/Users/ashka/PycharmProjects/bruteforce/main.py", line 91, in bruteforce
if bf_sha512(_, hash) is not None:
File "C:/Users/ashka/PycharmProjects/bruteforce/main.py", line 23, in bf_sha512
passwords = [functools.reduce(operator.add, (p)) for p in itertools.product(chars, repeat=n)]
File "C:/Users/ashka/PycharmProjects/bruteforce/main.py", line 23, in <listcomp>
passwords = [functools.reduce(operator.add, (p)) for p in itertools.product(chars, repeat=n)]
MemoryError
Process finished with exit code 1
出现错误的代码区域:
def bf_sha512(n, hash, chars):
print(' ')
print('Testing all possible passwords with ' + str(n) + ' characters... [' + str(int(chars.__len__())**n) + ']')
time.sleep(1)
with tqdm(total=int(chars.__len__())**n) as pbar:
count = 0
for password in [functools.reduce(operator.add, p) for p in itertools.product(chars, repeat=n)]:
count += 1
pbar.update(1)
if hashlib.sha512(password.encode()).hexdigest() == hash:
print('Needed attempts: ' + str(count))
print(' ')
print("Hash: " + hash)
print("Passwort: " + password)
pbar.close()
return password
pbar.close()
return None
我什至试图删除所有装饰线,如进度条和计数,但它还是崩溃了。