-from support.utilities import *
-from support.language_models import *
-from cipher.column_transposition import transpositions, transpositions_of
-
-from logger import logger
+from szyfrow.support.utilities import *
+from szyfrow.support.language_models import *
+# from szyfrow.column_transposition import transpositions, transpositions_of
# Where each piece of text ends up in the AMSCO transpositon cipher.
# 'index' shows where the slice appears in the plaintext, with the slice
# Where each piece of text ends up in the AMSCO transpositon cipher.
# 'index' shows where the slice appears in the plaintext, with the slice
grid shows the index of that slice and the start and end positions of the
plaintext that go to make it up.
grid shows the index of that slice and the start and end positions of the
plaintext that go to make it up.
fillpattern=(1, 2)) # doctest: +NORMALIZE_WHITESPACE
[[AmscoSlice(index=3, start=4, end=6),
AmscoSlice(index=2, start=3, end=4),
fillpattern=(1, 2)) # doctest: +NORMALIZE_WHITESPACE
[[AmscoSlice(index=3, start=4, end=6),
AmscoSlice(index=2, start=3, end=4),
current_fillpattern = list(reversed(current_fillpattern))
return [transpose(r, transpositions) for r in grid]
current_fillpattern = list(reversed(current_fillpattern))
return [transpose(r, transpositions) for r in grid]
fillpattern=(1,2), fillstyle=AmscoFillStyle.reverse_each_row):
"""AMSCO transposition encipher.
fillpattern=(1,2), fillstyle=AmscoFillStyle.reverse_each_row):
"""AMSCO transposition encipher.
- >>> amsco_transposition_encipher('hellothere', 'abc', fillpattern=(1, 2))
+ >>> amsco_encipher('hellothere', 'abc', fillpattern=(1, 2))
- >>> amsco_transposition_encipher('hellothere', 'abc', fillpattern=(2, 1))
+ >>> amsco_encipher('hellothere', 'abc', fillpattern=(2, 1))
- >>> amsco_transposition_encipher('hellothere', 'acb', fillpattern=(1, 2))
+ >>> amsco_encipher('hellothere', 'acb', fillpattern=(1, 2))
- >>> amsco_transposition_encipher('hellothere', 'acb', fillpattern=(2, 1))
+ >>> amsco_encipher('hellothere', 'acb', fillpattern=(2, 1))
- >>> amsco_transposition_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 2))
+ >>> amsco_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 2))
- >>> amsco_transposition_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 2), fillstyle=AmscoFillStyle.continuous)
+ >>> amsco_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 2), fillstyle=AmscoFillStyle.continuous)
- >>> amsco_transposition_encipher('hereissometexttoencipher', 'cipher', fillpattern=(2, 1))
+ >>> amsco_encipher('hereissometexttoencipher', 'cipher', fillpattern=(2, 1))
- >>> amsco_transposition_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 3, 2))
+ >>> amsco_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 3, 2))
- >>> amsco_transposition_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 3, 2), fillstyle=AmscoFillStyle.continuous)
+ >>> amsco_encipher('hereissometexttoencipher', 'cipher', fillpattern=(1, 3, 2), fillstyle=AmscoFillStyle.continuous)
fillpattern=fillpattern, fillstyle=fillstyle)
ct_as_grid = [[message[s.start:s.end] for s in r] for r in grid]
return combine_every_nth(ct_as_grid)
fillpattern=fillpattern, fillstyle=fillstyle)
ct_as_grid = [[message[s.start:s.end] for s in r] for r in grid]
return combine_every_nth(ct_as_grid)
fillpattern=(1,2), fillstyle=AmscoFillStyle.reverse_each_row):
"""AMSCO transposition decipher
fillpattern=(1,2), fillstyle=AmscoFillStyle.reverse_each_row):
"""AMSCO transposition decipher
- >>> amsco_transposition_decipher('hoteelhler', 'abc', fillpattern=(1, 2))
+ >>> amsco_decipher('hoteelhler', 'abc', fillpattern=(1, 2))
- >>> amsco_transposition_decipher('hetelhelor', 'abc', fillpattern=(2, 1))
+ >>> amsco_decipher('hetelhelor', 'abc', fillpattern=(2, 1))
- >>> amsco_transposition_decipher('hotelerelh', 'acb', fillpattern=(1, 2))
+ >>> amsco_decipher('hotelerelh', 'acb', fillpattern=(1, 2))
- >>> amsco_transposition_decipher('hetelorlhe', 'acb', fillpattern=(2, 1))
+ >>> amsco_decipher('hetelorlhe', 'acb', fillpattern=(2, 1))
- >>> amsco_transposition_decipher('hetcsoeisterereipexthomn', 'cipher', fillpattern=(1, 2))
+ >>> amsco_decipher('hetcsoeisterereipexthomn', 'cipher', fillpattern=(1, 2))
- >>> amsco_transposition_decipher('hecsoisttererteipexhomen', 'cipher', fillpattern=(1, 2), fillstyle=AmscoFillStyle.continuous)
+ >>> amsco_decipher('hecsoisttererteipexhomen', 'cipher', fillpattern=(1, 2), fillstyle=AmscoFillStyle.continuous)
- >>> amsco_transposition_decipher('heecisoosttrrtepeixhemen', 'cipher', fillpattern=(2, 1))
+ >>> amsco_decipher('heecisoosttrrtepeixhemen', 'cipher', fillpattern=(2, 1))
- >>> amsco_transposition_decipher('hxtomephescieretoeisnter', 'cipher', fillpattern=(1, 3, 2))
+ >>> amsco_decipher('hxtomephescieretoeisnter', 'cipher', fillpattern=(1, 3, 2))
- >>> amsco_transposition_decipher('hxomeiphscerettoisenteer', 'cipher', fillpattern=(1, 3, 2), fillstyle=AmscoFillStyle.continuous)
+ >>> amsco_decipher('hxomeiphscerettoisenteer', 'cipher', fillpattern=(1, 3, 2), fillstyle=AmscoFillStyle.continuous)
fillpattern=fillpattern, fillstyle=fillstyle)
transposed_sections = [s for c in [l for l in zip(*grid)] for s in c]
plaintext_list = [''] * len(transposed_sections)
fillpattern=fillpattern, fillstyle=fillstyle)
transposed_sections = [s for c in [l for l in zip(*grid)] for s in c]
plaintext_list = [''] * len(transposed_sections)
"It is a truth universally acknowledged, that a single man in \
possession of a good fortune, must be in want of a wife. However \
little known the feelings or views of such a man may be on his \
"It is a truth universally acknowledged, that a single man in \
possession of a good fortune, must be in want of a wife. However \
little known the feelings or views of such a man may be on his \
(6, 1, 0, 4, 5, 3, 2): ['keyword']}, \
patterns=[(1, 2)]) # doctest: +ELLIPSIS
(((2, 0, 5, 3, 1, 4, 6), (1, 2), <AmscoFillStyle.continuous: 1>), -709.4646722...)
(6, 1, 0, 4, 5, 3, 2): ['keyword']}, \
patterns=[(1, 2)]) # doctest: +ELLIPSIS
(((2, 0, 5, 3, 1, 4, 6), (1, 2), <AmscoFillStyle.continuous: 1>), -709.4646722...)
"It is a truth universally acknowledged, that a single man in \
possession of a good fortune, must be in want of a wife. However \
little known the feelings or views of such a man may be on his \
"It is a truth universally acknowledged, that a single man in \
possession of a good fortune, must be in want of a wife. However \
little known the feelings or views of such a man may be on his \
def amsco_break_worker(message, transposition,
pattern, fillstyle, fitness):
def amsco_break_worker(message, transposition,
pattern, fillstyle, fitness):
fillpattern=pattern, fillstyle=fillstyle)
fit = fitness(sanitise(plaintext))
fillpattern=pattern, fillstyle=fillstyle)
fit = fitness(sanitise(plaintext))
- logger.debug('AMSCO transposition break attempt using key {0} and pattern'
- '{1} ({2}) gives fit of {3} and decrypt starting: '
- '{4}'.format(
- transposition, pattern, fillstyle, fit,
- sanitise(plaintext)[:50]))
return (transposition, pattern, fillstyle), fit
if __name__ == "__main__":
return (transposition, pattern, fillstyle), fit
if __name__ == "__main__":