Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import hashlib
- import random
- import string
- import time
- diff = 5
- thread_num = 4
- calcs = 10**(diff+1) #Stupid rule, please dont use.
- threads=[]
- h=""
- def generate_string(diff):
- return str(time.time()) + ''.join([random.choice(list(string.ascii_lowercase)) for i in range(2**(10-diff))])
- def generate_chal(diff):
- return ''.join([random.choice(list(string.hexdigits)) for i in range(diff)])
- def pow(diff, string, chal, r, tn):
- n = r[0]
- #print("Running in range {0} to {1}".format(r[0],r[1]))
- #comp = False
- while n <= r[1]:
- h_s = string + str(n)
- h = hashlib.sha256(h_s.encode('utf-8')).hexdigest()
- if str(h)[:diff].upper() == chal.upper():
- print [h, h_s, n, tn]
- return None, None, None
- #comp=True
- else:
- n += 1
- #print("Didnt find any in range {0} to {1}".format(r[0],r[1]))
- return None, None, None
- for i in range(200):
- chal = generate_chal(diff) if not h else h[-diff::]
- s = generate_string(diff)
- for tn in range(thread_num):
- t = threading.Thread(target=pow, args=(diff, s, chal, [calcs/thread_num*tn,calcs/thread_num*(tn+1)], tn))
- threads.append(t)
- t.start()
- #print("Proof {0} for {1} with chal {2} generated hash {3} with range {4}".format(n, s, chal, h, r))
Add Comment
Please, Sign In to add comment