The Spartan scytale dates back to ca. 500 B.C., making it one of the earliest encryption devices known. It was used by the Spartan Military for encoding messages sent between commanders. The scytale consisted of a ribbon wrapped around a dowel of a particular diameter and length. The secret message was written left to right on the ribbon when it was wrapped around the dowel. The ribbon was then removed from the dowel, and only the ribbon was transported to the other field commander who had an identical dowel that could be used to decode the message. If the ribbon was intercepted, is seemingly contained just a jumble of letters.
scytale
Scytale

The following example illustrates how the scytale works. Assume we are working with a dowel having a diameter allowing to write four letters on the ribbon before it wraps again around the dowel. If we want to encode the message "Help me I am under attack", the entire text can be written over seven columns (of which the last three do not use one of the positions). Encoding the text comes down to writing the text from left to right, and from top to bottom on the ribbon.

--------+---+---+---+---+---+---+---+---+----
        | H | e | l | p |   | m | e | * |
    +---|   | I |   | a | m |   | u | * |
    | * | n | d | e | r |   | a | t |---+
    | * | t | a | c | k | * | * | * |
----+---+---+---+---+---+---+---+---+--------

After the ribbon has been released from the dowel, the encoded message reads as "H nteIdal ecpark m m aeut". This indeed has turned the message into an incomprehensible series of letters. To decode the text, the ribbon can be wrapped again around a dowel with the same diameter, after which the original text can be read from left to right, and top to bottom.

Assignment

Example

>>> encode('Help me I am under attack', 4)
'H nteIdal ecpark m m aeut'

>>> decode('H nteIdal ecpark m m aeut', 4)
'Help me I am under attack'

>>> encode('Always look on the bright side of life.', 7)
'A o t fllnb oewo rsf.aotii ykhgdls ehei'

>>> decode('A o t fllnb oewo rsf.aotii ykhgdls ehei', 7)
'Always look on the bright side of life.'