Ignore:
Timestamp:
12/06/12 18:35:28 (12 years ago)
Author:
tmorgan
Message:

added simple encode/decode command line tools

fixed problem with percent encoding by allowing for a third result of tests

implemented (untested) resumption of decryption for POA

more POA documentation and logging

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/bletchley/blobtools.py

    r1 r20  
    4141    def isExample(self, blob):
    4242        sblob = frozenset(blob)
    43         return ((self.charset == None or sblob.issubset(self.charset)) and self.extraTests(blob))
     43        if self.charset != None and not sblob.issubset(self.charset):
     44            return False
     45        return self.extraTests(blob)
    4446   
    4547    def extraTests(self, blob):
     48        """May return True, False, or None, for is an example, isn't an
     49        example, or unknown, respectively.
     50
     51        """
    4652        return True
    4753
     
    254260        chunks = blob.split('%')
    255261        if len(chunks) < 2:
    256             return False
     262            return None
    257263        for c in chunks[1:]:
    258264            if len(c) < 2:
     
    320326
    321327def possibleEncodings(blob):
    322     ret_val = set()
     328    likely = set()
     329    possible = set()
    323330    for name,encoding in encodings.items():
    324         if encoding.isExample(blob):
    325             ret_val.add(name)
    326     return ret_val
     331        result = encoding.isExample(blob)
     332        if result == True:
     333            likely.add(name)
     334        elif result == None:
     335            possible.add(name)
     336    return likely,possible
    327337
    328338
    329339def encodingIntersection(blobs):
    330340    ret_val = set(encodings.keys())
     341    p = set(encodings.keys())
    331342    for b in blobs:
    332         ret_val &= possibleEncodings(b)
    333 
    334     return ret_val
     343        likely,possible = possibleEncodings(b)
     344        ret_val &= likely | possible
     345        p &= possible
     346    return ret_val - p
    335347
    336348
     
    404416
    405417
     418#XXX: move this to buffertools
    406419def smartPermutateBlobs(blobs, block_size=8):
    407420    """
Note: See TracChangeset for help on using the changeset viewer.