首页 > 解决方案 > 提高 python sha1 hash bruteforcer 的性能

问题描述

我正在使用 python 中的 sha1 和 base64 制作我的自定义哈希暴力破解器。但是,它的工作速度非常慢。我阅读了我可以使用的三个模块:threading、concurrent.future 和 multiprocessing。有人能说出我应该使用的这些之间的区别,以及为什么其他的不如所选的吗?另外,请告诉我我能做些什么来加快这段代码的速度。这是代码:

import time
import hashlib
import itertools

charset = "abcdefghijklmnopqrstuvwxyz0123456789"
good = "" #here I supply the hash

start = time.time()

def encrypt(password):
    hsah = hashlib.sha1(password).digest()
    hsah = hsah.encode("base64")[:-1] + "" #here I have something like 'salt' which is needed
    hsah = hashlib.sha1(hsah).hexdigest()
    if hsah == good:
        print "password found!", password
        end = time.time()
        roz = end - start
        print roz
        exit()

passwords = itertools.product(charset, repeat=7)

for password in passwords:
    encrypt("".join(password))

标签: pythonperformancehashsha1brute-force

解决方案


推荐阅读