Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import subprocess
- import string
- POW_BITS = 25
- def random_string(n):
- return ''.join(random.choice(string.ascii_lowercase) for _ in range(n))
- def check_pow():
- r = random_string(10)
- # The user is asked to run this command in their terminal
- print(f"hashcash -mb{POW_BITS} {r}") # $ hashcash -mb25 <random_string>
- # hashcash calculates the opposing hash, and the user copy pastes it into solution
- solution = input("Solution:").strip()
- # Check that the solution is correct
- if subprocess.call(["hashcash", f"-cdb{POW_BITS}", "-r", r, solution],
- cwd="/tmp",
- stdout=subprocess.DEVNULL,
- stderr=subprocess.DEVNULL) != 0:
- raise Exception("Invalid PoW")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement