[Pgp-tools-commit] r600 - trunk/gpgparticipants

Peter Palfrader weasel at moszumanska.debian.org
Wed Apr 23 10:30:26 UTC 2014


Author: weasel
Date: 2014-04-23 10:30:26 +0000 (Wed, 23 Apr 2014)
New Revision: 600

Modified:
   trunk/gpgparticipants/gpgparticipants-prefill
   trunk/gpgparticipants/gpgparticipants-prefill.1
Log:
gpgparticipants-prefill: add --max-length and --prefix options

Modified: trunk/gpgparticipants/gpgparticipants-prefill
===================================================================
--- trunk/gpgparticipants/gpgparticipants-prefill	2014-04-23 10:30:23 UTC (rev 599)
+++ trunk/gpgparticipants/gpgparticipants-prefill	2014-04-23 10:30:26 UTC (rev 600)
@@ -9,6 +9,8 @@
 
 __license__ = "MIT"
 
+# also Copyright 2014 Peter Palfrader
+
 # Permission is hereby granted, free of charge, to any person
 # obtaining a copy of this software and associated documentation
 # files (the "Software"), to deal in the Software without
@@ -35,6 +37,7 @@
 import hashlib
 import getopt
 
+hexdigits = "0123456789abcdef"
 
 def insertspaces(s):
     """Inserts a space after every 4-th character, and three spaces after every
@@ -49,14 +52,17 @@
     return out
 
 
-def range_hex(length):
+def range_hex(length, fixed_prefix=''):
     """Give all hex-strings from 00...0 until ff...f of given length."""
 
     if length == 0:
         yield ""
-
+    elif len(fixed_prefix) > 0:
+      prefix = fixed_prefix[0]
+      for postfix in range_hex(length-1, fixed_prefix[1:]):
+        yield prefix + postfix
     elif length == 1:
-        for c in "0123456789abcdef":
+        for c in hexdigits:
             yield c
     elif length > 1:
         for prefix in range_hex(length-1):
@@ -83,6 +89,7 @@
                        is given then the program immediately jumps to the next
                        length.
   --min-length NUM     Start search with given length.
+  --max-length NUM     Stop search with given length.
 
 """.format(sys.argv[0]))
 
@@ -91,34 +98,39 @@
 
     fastforward = False
     minlength = 1
+    maxlength = 32
+    prefix = ''
 
-    optlist, args = getopt.getopt(sys.argv[1:], 'h', ['fastforward', 'min-length=', 'help'])
+    optlist, args = getopt.getopt(sys.argv[1:], 'h', ['fastforward', 'min-length=', 'max-length=', 'prefix=', 'help'])
     for o, a in optlist:
-
         if o in ("-h", "--help"):
             usage()
             exit(0)
-
-        if o in ("--fastforward"):
+        elif o in ("--fastforward"):
             fastforward = True
-
-        if o in ("--min-length"):
+        elif o in ("--min-length"):
             minlength = int(a)
+        elif o in ("--max-length"):
+            maxlength = int(a)+1
+        elif o in ("--prefix"):
+            prefix = a.lower()
 
     if len(args) < 2:
-        print >>sys.stderr, "You need to give two filenames."""
+        print >>sys.stderr, "You need to give two filenames."
         exit(1)
+    if not all(c in hexdigits for c in prefix):
+        print >>sys.stderr, "Invalid prefix."
+        exit(1)
 
     emptyfile = open(args[0]).read()
 
     idx = emptyfile.find("SHA256 Checksum:")
     idx = emptyfile.find("_", idx)
 
-    for l in range(minlength, 32):
+    for l in range(minlength, maxlength):
         print "Looking at length", l
 
-        for h in range_hex(l):
-
+        for h in range_hex(l, prefix):
             H = insertspaces(h.upper())
             filledfile = emptyfile[:idx] + H + emptyfile[idx+len(H):]
             actual = hashlib.sha256(filledfile).hexdigest()

Modified: trunk/gpgparticipants/gpgparticipants-prefill.1
===================================================================
--- trunk/gpgparticipants/gpgparticipants-prefill.1	2014-04-23 10:30:23 UTC (rev 599)
+++ trunk/gpgparticipants/gpgparticipants-prefill.1	2014-04-23 10:30:26 UTC (rev 600)
@@ -3,15 +3,15 @@
 gpgparticipants-prefill \- insert checksum-digits in a gpgparticicpants' form
 .SH SYNOPSIS
 .B gpgparticipants-prefill
-\fIemptylist\fP \fIfilledlist\fP
+[\fIOPTIONS\fP] \fIEMPTYLIST\fP \fIFILLEDLIST\fP
 .SH DESCRIPTION
 .B gpgparticipants-prefill
-takes a file produced by \fBgpgparticipants\fP (\fIemptylist\fP) and trys to fill in some
+takes a file produced by \fBgpgparticipants\fP (\fIEMPTYLIST\fP) and tries to fill in some
 digits into the SHA256 field such that the resulting list actually has a SHA256
 checksum that starts with those digits.  In other words, it tries to produce a
 file that hashes to a checksum that is partially written down in the file.
-Whenever a match is found a file with the digits filled in is written to
-\fIfilledlist\fP\fB.\fP\fIDIGITS\fP.
+Whenever a match is found, a file with the digits filled in is written to
+\fIFILLEDLIST\fP\fB.\fP\fIDIGITS\fP.
 
 .SH OPTIONS
 
@@ -19,12 +19,17 @@
 Print the usage text.
 
 .IP "\fB\-\-fastforward\fP" 8
-If a match is found of given length and \-\-fastforward is given then the program
-immediately jumps to the next length.
+If a match is found of some length, immediately jump to the next length.
 
 .IP "\fB\-\-min-length\fP \fINUM\fP" 8
 Start search with given length.
 
+.IP "\fB\-\-max-length\fP \fINUM\fP" 8
+Stop search after the given length.
+
+.IP "\fB\-\-prefix\fP \fIPREFIX\fP" 8
+Only consider hex strings starting with \fIPREFIX\fP.
+
 .SH SEE ALSO
 .BR gpgparticipants (1)
 .SH AUTHOR




More information about the Pgp-tools-commit mailing list