Skip to content

Instantly share code, notes, and snippets.

@bortzmeyer
Created June 18, 2019 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bortzmeyer/e9e1d47944856d75fad780f8e54b1c4c to your computer and use it in GitHub Desktop.
Save bortzmeyer/e9e1d47944856d75fad780f8e54b1c4c to your computer and use it in GitHub Desktop.
Programme de minage pour l'école d'été de cybersécurité, cours Bitcoin
#!/usr/bin/env python3

import random

def asciisum(s):
    result = 0
    for c in s:
        result += ord(c)
    return result

def find(seed):
    found = False
    while not found:
        nonce = gen.randint(0, 1000)
        possible = asciisum(str(asciisum("%s%s" % (seed, str(nonce)))))
        if possible % 3 == 0 and possible % 5 ==0:
            print("Found: nonce %s, hash %s" % (nonce, possible))
            found = True
    return possible

gen = random.Random()
# Current state of the chain
next = "42"
for transaction in ("AD5", "BC9", "BD7", "CA3"):
    next = find(transaction + str(next))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment