grimoire/python/hash-quine.py

41 lines
824 B
Python

import hashlib
import signal
def rotate(seq):
last_seq = True
mod_next = True
idx = 0
while mod_next and idx < len(seq):
mod_next = False
if last_seq:
last_seq = seq[idx] == ord("f")
if seq[idx] == ord("9"):
seq[idx] = ord("a")
elif seq[idx] == ord("f"):
seq[idx] = ord("0")
mod_next = True
else:
seq[idx] += 1
idx += 1
return not last_seq
hash_str = ""
show = lambda sig, frame: print("\rcurrently on:", hash_str)
hash_bytes = [ord("0") for _ in range(64)]
should_rotate = True
signal.signal(signal.SIGTSTP, show)
while should_rotate:
hash_str = "".join([chr(byte) for byte in hash_bytes[::-1]])
sha_hash = hashlib.sha256(hash_str.encode("utf-8")).hexdigest()
if hash_str == sha_hash:
print(hash_str)
should_rotate = rotate(hash_bytes)