Skip to content

Instantly share code, notes, and snippets.

@micromaomao
Created May 2, 2015 09:56
Show Gist options
  • Save micromaomao/215913ff012b94038880 to your computer and use it in GitHub Desktop.
Save micromaomao/215913ff012b94038880 to your computer and use it in GitHub Desktop.
FindZeroHash - My python beginning program, my first python program!
#!/usr/bin/python
import sha;
import sys;
import time;
def checkifzero(str, count):
sa = sha.new(str).digest();
return sa.startswith('\x00' * count);
if len(sys.argv) != 5:
sys.stderr.write ("""\
Command: ./findHash.py <start-text-file> <from> <to> <zero count>
Wrote by wtm""");
exit(1);
stfName = sys.argv[1];
stfF = open(stfName, 'r');
stfCt = stfF.read();
zeroc = int(sys.argv[4]);
sys.stderr.write("Finding \"" + stfCt + ("_" * zeroc) + "\" . sha1 startswith " + ("0" * zeroc) + "\n");
start = int(sys.argv[2]);
end = int(sys.argv[3]);
sys.stderr.write("From " + str(start) + " to " + str(end) + "\n");
now = start;
lastPgr = time.time();
while now < end:
ifc = checkifzero(stfCt + str(now), zeroc);
if ifc:
sys.stderr.write("Find "+stfCt);
sys.stderr.flush();
sys.stdout.write(str(now));
sys.stdout.flush();
sys.stderr.write(" gots a sha1 starts with ");
sys.stderr.write("0" * zeroc);
sys.stderr.write(" ");
sys.stdout.write("\n");
sys.stderr.flush();
elif time.time() - lastPgr > 20:
sys.stderr.write(" Finding to " + str(now) + "\n");
lastPgr = time.time();
now+=1;
sys.stderr.write("Done.\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment