Caesar Cypher
Created on Jan. 17, 2017 by Antoine Mazières
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']Each letter has a position in this list. a
is 1, b
is 2, j
is 10, etc...
Caesar cypher hide information by using a key which is a positive number to add to the position of the original letter, the result being the position of the encrypted letter.
a
with key == 2
gives c
If the key brings you to the end of the alphabet, you continue to count from the begining, such as:
a
with key == 28
gives c
To decypher, or decrypt, the message, you apply the same procedure moving backward on the alphabet.
You must provide the functions caesar_cypher_encrypt(s, key)
and
caesar_cypher_decrypt(s, key)
where:
Write a function combining two strings so they are displayed side by side, separated by a column of pipe (
|
) symbols, like this:1 2 3 4 5
Lorem ipsum dolor sit amet, consectetur|Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed non risus. |adipiscing elit. Sed non risus. Suspendisse lectus tortor, dignissim |Suspendisse lectus tortor, dignissim sit amet, adipiscing nec, utilisez sed |sit amet, adipiscing nec, utilisez sed sin dolor. |sin dolor.
This function will also take a 3rd, optional, parameter named
width
representing the maximum width allowed, defaulting to 79, so the function prototype is:1 2
def sidebyside(left, right, width=79): ...
The width should never be overflow, even with the middle
|
column, and the two column should be of the exact same width, so ther's two cases:- For an odd width: keep 1 for the middle
|
column, the rest is divisible by two. - For an even width: to avoid overflow, drop one column.
The function should returns
is a string (letter, word, sentence, etc).- For an odd width: keep 1 for the middle
key
is a positive integer, the key of the caesar cypher.
Your implementation should only transform uppercase and lowercase ASCII letters. Special characters, numbers and letters with accents should not be transformed.
Your function shall not print but return the encoded/decoded string.
If you've written it in a caesar.py
file, you can test it with:
1 2 3 4 5 6 7 8 9 |
|
- Ctrl-Enter: Send your code to the correction bot.
- Escape: Get back to the instructions tab.