Skip to content

Instantly share code, notes, and snippets.

@Wheest
Created April 19, 2020 08:18
Show Gist options
  • Save Wheest/723afaa84e143b27afec68c621e7a202 to your computer and use it in GitHub Desktop.
Save Wheest/723afaa84e143b27afec68c621e7a202 to your computer and use it in GitHub Desktop.
Generate a proof of work for a custom input and prefix, using MD5
from hashlib import md5
import argparse
parser = argparse.ArgumentParser(description='Proof of work')
parser.add_argument('--input_string', default='chungus',
help='String to compute proof of work on')
parser.add_argument('--prefix', default='000',
help='Required prefix for PoW - longer is more difficult')
args = parser.parse_args()
complete = False
n = 0
while not complete:
curr_string = f'{args.input_string} (nonce: {str(n)})'.encode('utf-8')
curr_hash = md5(curr_string).hexdigest()
n = n + 1
if curr_hash.startswith(args.prefix):
print(curr_hash)
print(curr_string)
complete = True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment