Advertisement
Guest User

Untitled

a guest
May 27th, 2020
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.76 KB | None | 0 0
  1. import random
  2. import subprocess
  3. import string
  4.  
  5. POW_BITS = 25
  6.  
  7. def random_string(n):
  8.     return ''.join(random.choice(string.ascii_lowercase) for _ in range(n))
  9.  
  10. def check_pow():
  11.     r = random_string(10)
  12.  
  13.     # The user is asked to run this command in their terminal
  14.     print(f"hashcash -mb{POW_BITS} {r}") # $ hashcash -mb25 <random_string>
  15.  
  16.     # hashcash calculates the opposing hash, and the user copy pastes it into solution
  17.     solution = input("Solution:").strip()
  18.  
  19.     # Check that the solution is correct
  20.     if subprocess.call(["hashcash", f"-cdb{POW_BITS}", "-r", r, solution],
  21.                        cwd="/tmp",
  22.                        stdout=subprocess.DEVNULL,
  23.                        stderr=subprocess.DEVNULL) != 0:
  24.         raise Exception("Invalid PoW")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement