X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=szyfrow%2Fpolybius.py;h=d037ec9c0b212d03784fe64744f0c42eeb08c64a;hb=748b5cceaa346d3097c58229ea04ead0c7e3f48e;hp=965c3bba2441fc810733d7c2eae82955576d2c76;hpb=a870050db6bc974b1bb0d132001750b6624fb43f;p=szyfrow.git

diff --git a/szyfrow/polybius.py b/szyfrow/polybius.py
index 965c3bb..d037ec9 100644
--- a/szyfrow/polybius.py
+++ b/szyfrow/polybius.py
@@ -1,9 +1,11 @@
+"""Simple digraph substitution cipher, using the 
+[Polybius square](https://en.wikipedia.org/wiki/Polybius_square). Enciphering
+and deciphering, and a couple of ways to break these ciphers.
+"""
 import multiprocessing 
-from support.utilities import *
-from support.language_models import *
-from cipher.keyword_cipher import KeywordWrapAlphabet, keyword_cipher_alphabet_of
-
-from logger import logger
+from szyfrow.support.utilities import *
+from szyfrow.support.language_models import *
+from szyfrow.keyword_cipher import KeywordWrapAlphabet, keyword_cipher_alphabet_of
 
 def polybius_grid(keyword, column_order, row_order, letters_to_merge=None,
                   wrap_alphabet=KeywordWrapAlphabet.from_a):
@@ -50,7 +52,7 @@ def polybius_reverse_grid(keyword, column_order, row_order, letters_to_merge=Non
 
 
 def polybius_flatten(pair, column_first):
-    """Convert a series of pairs into a single list of characters"""
+    """Convert a pair of characters into a single string."""
     if column_first:
         return str(pair[1]) + str(pair[0])
     else:
@@ -62,7 +64,6 @@ def polybius_encipher(message, keyword, column_order, row_order,
     """Encipher a message with Polybius cipher, using a keyword to rearrange
     the alphabet
 
-
     >>> polybius_encipher('this is a test message for the ' \
           'polybius decipherment', 'elephant', \
           [1, 2, 3, 4, 5], [1, 2, 3, 4, 5], \
@@ -103,13 +104,15 @@ def polybius_decipher(message, keyword, column_order, row_order,
     column_index_type = type(column_order[0])
     row_index_type = type(row_order[0])
     if column_first:
-        pairs = [(column_index_type(p[1]), row_index_type(p[0])) for p in chunks(message, 2)]
+        pairs = [(column_index_type(p[1]), row_index_type(p[0])) 
+          for p in chunks(message, 2)]
     else:
-        pairs = [(row_index_type(p[0]), column_index_type(p[1])) for p in chunks(message, 2)]
+        pairs = [(row_index_type(p[0]), column_index_type(p[1])) 
+          for p in chunks(message, 2)]
     return cat(grid[p] for p in pairs if p in grid)
 
 
-def polybius_break_mp(message, column_labels, row_labels,
+def polybius_break(message, column_labels, row_labels,
                       letters_to_merge=None,
                       wordlist=keywords, fitness=Pletters,
                       number_of_solutions=1, chunksize=500):
@@ -172,12 +175,6 @@ def polybius_break_worker(message, keyword, wrap_alphabet,
         fit = fitness(plaintext)
     else:
         fit = float('-inf')
-    logger.debug('Polybius break attempt using key {0} (wrap={1}, merging {2}), '
-                 'columns as {3}, rows as {4} (column_first={5}) '
-                 'gives fit of {6} and decrypt starting: '
-                 '{7}'.format(keyword, wrap_alphabet, letters_to_merge,
-                              column_order, row_order, column_first,
-                              fit, sanitise(plaintext)[:50]))
     return (keyword, wrap_alphabet, column_order, row_order, column_first), fit
 
 if __name__ == "__main__":