projects
/
cipher-training.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
f23ebe9
)
Incorporated changes from presentation branch
author
Neil Smith
<neil.git@njae.me.uk>
Wed, 2 Jul 2014 21:20:00 +0000
(22:20 +0100)
committer
Neil Smith
<neil.git@njae.me.uk>
Wed, 2 Jul 2014 21:20:00 +0000
(22:20 +0100)
cipher.py
patch
|
blob
|
history
diff --git
a/cipher.py
b/cipher.py
index e39abce8adf96fa495b631370057ba1470bc6525..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!']
"""
>>> 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):
return [''.join(l) for l in zip_longest(*split_text, fillvalue=fillvalue)]
def combine_every_nth(split_text):
@@
-471,15
+471,18
@@
def scytale_encipher(message, rows, fillvalue=' '):
>>> scytale_encipher('thequickbrownfox', 4)
'tubnhirfecooqkwx'
>>> scytale_encipher('thequickbrownfox', 5)
>>> scytale_encipher('thequickbrownfox', 4)
'tubnhirfecooqkwx'
>>> scytale_encipher('thequickbrownfox', 5)
- 'tubn
hirfecooqkwx
'
+ 'tubn
hirf ecoo qkwx
'
>>> scytale_encipher('thequickbrownfox', 6)
'tqcrnxhukof eibwo '
>>> scytale_encipher('thequickbrownfox', 7)
>>> scytale_encipher('thequickbrownfox', 6)
'tqcrnxhukof eibwo '
>>> scytale_encipher('thequickbrownfox', 7)
- 'tqcrnx
hukof 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,
return column_transposition_encipher(message, transpositions,
- fill
columnwise=False, emptycolumnwise=Tru
e)
+ fill
value=fillvalue, fillcolumnwise=True, emptycolumnwise=Fals
e)
def scytale_decipher(message, rows):
"""Deciphers using the scytale transposition cipher.
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'
'thequickbrownfox '
>>> scytale_decipher('tubnhirfecooqkwx', 4)
'thequickbrownfox'
- >>> scytale_decipher('tubn
hirfecooqkwx
', 5)
- 'thequickbrownfox'
+ >>> scytale_decipher('tubn
hirf ecoo qkwx
', 5)
+ 'thequickbrownfox
'
>>> scytale_decipher('tqcrnxhukof eibwo ', 6)
'thequickbrownfox '
>>> scytale_decipher('tqcrnxhukof eibwo ', 6)
'thequickbrownfox '
- >>> scytale_decipher('tqcrnx
hukof 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,
return column_transposition_decipher(message, transpositions,
- fillcolumnwise=
False, emptycolumnwise=Tru
e)
+ fillcolumnwise=
True, emptycolumnwise=Fals
e)
if __name__ == "__main__":
if __name__ == "__main__":