Done transposition slides
[cipher-training.git] / cipher.py
index ba62d411a902e40f6bc1b259d2733111f891407d..a2df81bb5242967fe10e345f21c9158c5abf8850 100644 (file)
--- a/cipher.py
+++ b/cipher.py
@@ -27,7 +27,7 @@ def every_nth(text, n, fillvalue=''):
     >>> every_nth(string.ascii_lowercase, 5, fillvalue='!')
     ['afkpuz', 'bglqv!', 'chmrw!', 'dinsx!', 'ejoty!']
     """
-    split_text = [text[i:i+n] for i in range(0, len(text), n)]
+    split_text = chunks(text, n, fillvalue)
     return [''.join(l) for l in zip_longest(*split_text, fillvalue=fillvalue)]
 
 def combine_every_nth(split_text):
@@ -242,9 +242,9 @@ def affine_decipher(message, multiplier=1, adder=0, one_based=True):
 
 
 class Keyword_wrap_alphabet(Enum):
-    from_a = 0
-    from_last = 1
-    from_largest = 2
+    from_a = 1
+    from_last = 2
+    from_largest = 3
 
 
 def keyword_cipher_alphabet_of(keyword, wrap_alphabet=Keyword_wrap_alphabet.from_a):
@@ -471,15 +471,18 @@ def scytale_encipher(message, rows, fillvalue=' '):
     >>> scytale_encipher('thequickbrownfox', 4)
     'tubnhirfecooqkwx'
     >>> scytale_encipher('thequickbrownfox', 5)
-    'tubnhirfecooqkwx'
+    'tubn hirf ecoo qkwx '
     >>> scytale_encipher('thequickbrownfox', 6)
     'tqcrnxhukof eibwo '
     >>> scytale_encipher('thequickbrownfox', 7)
-    'tqcrnxhukof eibwo '
+    'tqcrnx hukof  eibwo  '
     """
-    transpositions = [i for i in range(math.ceil(len(message) / rows))]
+    # transpositions = [i for i in range(math.ceil(len(message) / rows))]
+    # return column_transposition_encipher(message, transpositions, 
+    #     fillvalue=fillvalue, fillcolumnwise=False, emptycolumnwise=True)
+    transpositions = [i for i in range(rows)]
     return column_transposition_encipher(message, transpositions, 
-        fillcolumnwise=False, emptycolumnwise=True)
+        fillvalue=fillvalue, fillcolumnwise=True, emptycolumnwise=False)
 
 def scytale_decipher(message, rows):
     """Deciphers using the scytale transposition cipher.
@@ -489,16 +492,19 @@ def scytale_decipher(message, rows):
     'thequickbrownfox  '
     >>> scytale_decipher('tubnhirfecooqkwx', 4)
     'thequickbrownfox'
-    >>> scytale_decipher('tubnhirfecooqkwx', 5)
-    'thequickbrownfox'
+    >>> scytale_decipher('tubn hirf ecoo qkwx ', 5)
+    'thequickbrownfox    '
     >>> scytale_decipher('tqcrnxhukof eibwo ', 6)
     'thequickbrownfox  '
-    >>> scytale_decipher('tqcrnxhukof eibwo ', 7)
-    'thequickbrownfox  '
+    >>> scytale_decipher('tqcrnx hukof  eibwo  ', 7)
+    'thequickbrownfox     '
     """
-    transpositions = [i for i in range(math.ceil(len(message) / rows))]
+    # transpositions = [i for i in range(math.ceil(len(message) / rows))]
+    # return column_transposition_decipher(message, transpositions, 
+    #     fillcolumnwise=False, emptycolumnwise=True)
+    transpositions = [i for i in range(rows)]
     return column_transposition_decipher(message, transpositions, 
-        fillcolumnwise=False, emptycolumnwise=True)
+        fillcolumnwise=True, emptycolumnwise=False)
 
 
 if __name__ == "__main__":