]>
git.sthu.org Git - pgp-tools.git/blob - gpgparticipants/gpgparticipants-prefill
2 """Fill in the first digits of the hash in a form created by gpgparticipants."""
6 __author__
= "Stefan Huber"
7 __email__
= "shuber@sthu.org"
8 __copyright__
= "Copyright 2013, Stefan Huber"
12 # Permission is hereby granted, free of charge, to any person
13 # obtaining a copy of this software and associated documentation
14 # files (the "Software"), to deal in the Software without
15 # restriction, including without limitation the rights to use,
16 # copy, modify, merge, publish, distribute, sublicense, and/or sell
17 # copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following
21 # The above copyright notice and this permission notice shall be
22 # included in all copies or substantial portions of the Software.
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
26 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
28 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
29 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
31 # OTHER DEALINGS IN THE SOFTWARE.
40 """Inserts a space after every 4-th character, and three spaces after every
41 8-th character of string s."""
48 out
= " ".join([ " ".join(inpacks(octp
, 4)) for octp
in inpacks(s
, 8)])
52 def range_hex(length
):
53 """Give all hex-strings from 00...0 until ff...f of given length."""
59 for c
in "0123456789abcdef":
62 for prefix
in range_hex(length
-1):
63 for postfix
in range_hex(1):
64 yield prefix
+ postfix
68 """Print --help text"""
71 {0} <emptylist> <filledlist>
75 Takes a file produced by gpgparticipants as <emptylist> and trys to fill in
76 some digits into the SHA256 field such that the resulting list actually has
77 a SHA256 checksum that starts with those digits. Whenever a match is found a
78 file with the digits filled in is written to `<filledlist>.DIGITS`.
82 --fastforward If a match is found of given length and --fastforward
83 is given then the programm immediately jumps to the next
85 --min-length NUM Start looking for hex strings of given length
87 """.format(sys
.argv
[0]))
89 if __name__
== "__main__":
94 optlist
, args
= getopt
.getopt(sys
.argv
[1:], 'h', ['fastforward', 'min-length='])
97 if o
in ("-h", "--help"):
101 if o
in ("--fastforward"):
104 if o
in ("--min-length"):
108 print >>sys
.stderr
, "You need to give two filenames."""
111 emptyfile = open(args[0]).read()
113 idx = emptyfile.find("SHA256 Checksum
:")
114 idx = emptyfile.find("_
", idx)
116 for l in range(minlength, 32):
117 print "Looking at length
", l
119 for h in range_hex(l):
121 H = insertspaces(h.upper())
122 filledfile = emptyfile[:idx] + H + emptyfile[idx+len(H):]
123 actual = hashlib.sha256(filledfile).hexdigest()
125 if actual[:len(h)] == h:
127 open(args[1] + "." + h, "w
").write(filledfile)