So I was trying to research what goes into generating a GIT commit hash and I thought I would try to personalize the cryptographic hash output a little bit. My computer isn’t that powerful but it may be possible to generate more zeros!
import time, hashlib, subprocess head = subprocess.check_output("git cat-file commit HEAD | sed -e 's/> .*$/> %d %s/'", shell=True) secs = int(time.time()) rnds = (secs - 99999999) offs = "-0500" begs = ("0" * 6) ghsh = "" while (not ghsh.startswith(begs)): rnds = (rnds + 1) comm = (head % (secs, offs, rnds, offs)) data = ("commit %d\0%s" % (len(comm), comm)) ghsh = hashlib.sha1(data).hexdigest() chk = raw_input("Commit hash [%s]?: " % (ghsh)).strip() if (chk.lower().startswith("y")): comd = ("GIT_COMMITTER_DATE='%d %s' git commit -a --amend --no-edit --date='%d %s'" % (rnds, offs, secs, offs)) subprocess.call(comd, shell=True)
2 thoughts on “Exploring GIT Commit Hashes & Generating Cryptographic Zeros”
I like that I’m not all the way there understanding it but I recognize things like hash and other features when dealing with crypto I know a bunch of legit sites that are free but maybe you can school meon the coding I’m learning but it’s tough
Cool toy, but why use python 2 exclusively? This makes it a lot less accessible to most Linux users these days (2022). Simply replace `raw_input` by `input`, decode head with `.decode()`, encode data with `data.encode()` and it will run with python 3. Might break python 2 compatibility, but who has that preinstalled these days anyways?