Created
May 6, 2022 02:19
-
-
Save erickclasen/9c1eb09791217ec1502d8f38c7c46731 to your computer and use it in GitHub Desktop.
Demonstrates SHA256 hashing. Shows a basic proof of work example as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Original seed idea from | |
https://www.pythoncentral.io/hashing-strings-with-python/ | |
''' | |
import hashlib | |
from datetime import datetime | |
mystring = input('Enter String to hash: ') | |
# Assumes the default UTF-8 | |
hash_object = hashlib.sha256(mystring.encode()) | |
print(hash_object.hexdigest()) | |
for DIF in range(1,32): | |
for n in range(1,1000000000000): | |
x = mystring + str(n) | |
hash_object = hashlib.sha256(x.encode()) | |
d = hash_object.hexdigest() | |
#print(x,d) | |
tally = 0 | |
for z in range(0,DIF): | |
if d[z] == '0': | |
tally += 1 | |
if tally == DIF: | |
break | |
timestamp = str(datetime.now()) | |
print(timestamp,DIF,x,d) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output, shows a hash of the word "hello"
Then it applies a nonce appended to hello to get hashes with zeros at the beginning, simulating proof of work for an example.
Shows timestamps to show how long it takes to generate the hashes as the difficulty rises.