Crack bcrypt using multiple cores
Using random pastebin examples I wrote a multi-core bcrypt. One bug to fix: after finding a match it doesn't exit early.
#!/usr/bin/python3
from passlib.hash import bcrypt
import os
import sys
import io
import multiprocessing
def chunks(l, n):
return [l[i:i+n] for i in range(0, len(l), n)]
def do_job(job_id, data_slice):
for item in data_slice:
correct = bcrypt.verify(item, hash)
if (correct):
print("Found: {0}".format(item))
exit()
def dispatch_jobs(data, job_number):
total = len(data)
chunk_size = total // job_number
slice = chunks(data, chunk_size)
jobs = []
for i, s in enumerate(slice):
j = multiprocessing.Process(target=do_job, args=(i, s))
jobs.append(j)
for j in jobs:
j.start()
if __name__ == '__main__':
num_processes = multiprocessing.cpu_count()
with io.open("orig.txt","r",encoding="ISO-8859-1") as f:
words = f.read().splitlines()
hash = input('hash to crack: ')
dispatch_jobs(words, num_processes)