3 __author__
= "Stefan Huber <shuber@sthu.org>"
11 """Inserts a space after every 4-th character, and three spaces after every
12 8-th character of string s."""
19 out
= " ".join([ " ".join(inpacks(octp
, 4)) for octp
in inpacks(s
, 8)])
23 def range_hex(length
):
24 """Give all hex-strings from 00...0 until ff...f of given length."""
30 for c
in "0123456789abcdef":
33 for prefix
in range_hex(length
-1):
34 for postfix
in range_hex(1):
35 yield prefix
+ postfix
39 """Print --help text"""
42 {0} <emptylist> <filledlist>
46 Takes a file produced by gpgparticipants as <emptylist> and trys to fill in
47 some digits into the SHA256 field such that the resulting list actually has
48 a SHA256 checksum that starts with those digits. Whenever a match is found a
49 file with the digits filled in is written to `<filledlist>.DIGITS`.
53 --fastforward If a match is found of given length and --fastforward
54 is given then the programm immediately jumps to the next
56 --min-length NUM Start looking for hex strings of given length
58 """.format(sys
.argv
[0]))
60 if __name__
== "__main__":
65 optlist
, args
= getopt
.getopt(sys
.argv
[1:], 'h', ['fastforward', 'min-length='])
68 if o
in ("-h", "--help"):
72 if o
in ("--fastforward"):
75 if o
in ("--min-length"):
79 print >>sys
.stderr
, "You need to give two filenames."""
82 emptyfile = open(args[0]).read()
84 idx = emptyfile.find("SHA256 Checksum
:")
85 idx = emptyfile.find("_
", idx)
87 for l in range(minlength, 32):
88 print "Looking at length
", l
90 for h in range_hex(l):
92 H = insertspaces(h.upper())
93 filledfile = emptyfile[:idx] + H + emptyfile[idx+len(H):]
94 actual = hashlib.sha256(filledfile).hexdigest()
96 if actual[:len(h)] == h:
98 open(args[1] + "." + H, "w
").write(filledfile)