首页 > 解决方案 > Python程序意外停止

问题描述

该程序是关于python中的哈希破解器。它基本上会遍历一个巨大的密码列表,然后对每个密码进行 md5 哈希并将其与我的哈希进行比较。它工作得很好,除非我在密码列表中输入超过第 4750 行的密码。它停在那里,程序结束,我不知道为什么。

这是我的代码

import os
try:
    import hashlib
except ModuleNotFoundError:
    os.system('pip3 install hashlib')
    import hashlib

def test_hash(target, string):
    hashed = hashlib.md5(string.encode('utf-8')).hexdigest()
    if target == hashed:
        print(f'Found coincidence at -> {string}')
        return 1
    else:
        return 0
target_hash = 'an-md5-hash'

if __name__ == '__main__':
    with open('passwordlist.txt', 'r') as file:
        count = 1
        while (line := file.readline().rstrip()):
            print(f'Trying passord {count} -> {line}')
            count += 1
            result = test_hash(target_hash, line)
            if result == 1:
                break
            else:
                continue

标签: pythonpython-3.x

解决方案


文件中一定有问题,可能是错误的行格式。我建议您在发生错误的行检查文件。


推荐阅读