The Caesar and Vigenre ciphers are two popular substitution ciphers, so named because letters are substituted for others in their usage. Named after Julius Caesar, who is said to have used it in personal and military communication, is one of the oldest and most widely known ciphers. The Vigenre Cipher was developed in the 1500s and has been attributed to French diplomat Blaise de Vigenre, although its actual origins are unclear.
For this assignment, you will always leave all characters that are not letters unchanged.
Plaintext message letters may be either upper or lower case, but you should output only upper case ciphertext.
Remember that the string function upper() gives back a version of its string that has all alphabet characters converted to upper case.
I.e.,
name = "Caesar"
print (name.upper())
will print out CAESAR
Note that you are writing two functions for each cryptosystem, an encrypt and a decrypt, so one partial test of the correctness of your work is whether first encrypting and then decrypting returns the original string (except that you may have converted some lower case letters to upper case).
You will write a total of four functions, each of which will take two inputs and return a string:
c_encrypt()
c_decrypt()
vig_encrypt()
vig_decrypt()
The first argument will be a string containing the plaintext (or clear text) message to be encrypted for the two encrypt functions, and a string containing a ciphertext to be decrypted. The second argument will be the key.
For this assignment, you will always leave all characters in plaintext or ciphertext that are not letters (i.e., spaces and punctuation marks) unchanged.
Plaintext message letters may be either upper or lower case, but you should output only upper case ciphertext.
Remember the string function upper() you used in lab.
Note that you are writing two functions for each cryptosystem, an encrypt and a decrypt, so one partial test of the correctness of your work is whether first encrypting and then decrypting returns the original string (except that you may have converted some lower case letters to upper case).
Caesar part of the homework: Write c_encrypt() and c_decrypt(), both of which take two arguments, the first one a string and the second one an integer key.
Both should return a string.
This will be much easier if both functions use the rotate() shift function you wrote for the lab.
As with the lab, you may not use the Python ord() or chr() functions
The Vigenre Cipher was more or less completely unbreakable from its introduction sometime in the 1500s until well into the 1800s.
The key in Vigenre is a key word that is used over and over again to give a different key to the Caesar cipher for each letter of the encryption (and decryption), with 'A', in good Python form, representing a rotation of 0. (We Pythonistas start at 0, not 1!)
So if the key is ABACUS, then we encrypt:
the first letter of our message with a Caesar cipher with a key/rotation of 0, because A is the first letter of the alphabet, the second letter with a key/rotation of 1 (for the 'B'), the third letter with a rotation of 0 (for the second 'A' of ABACUS), the fourth letter with a key/rotation of 2 for the 'C', the fifth letter with a key/rotation of 20 for the 'U', the sixth letter with a key/rotation of 18 for the 'S', and wrap back to the start of our keyword ABACUS and encrypt the seventh letter with a key/rotation of 0 for the first 'A' in ABACUS
Back in the 1800s people wanting to use this system would make use of a Vigenre square, also known as the tabula recta, shown in the middle of the Wikipedia entry for the Vigenre cipher, but we can use Python.
Vigenere part of the homework: Write vig_encrypt() and vig_decrypt() functions. Each takes two strings as inputs, with the first being the plaintext/ciphertext, and the second being the key. Both should be calling functions you wrote earlier to help make the work easier.
The key will be a string consisting only of letters, but the letters might be in upper, lower, or mixed case. Important: If the plaintext to be encrypted has non-alphabetic characters (e.g., spaces or punctuation):
Leave the non-alphabetic character unchanged just as you did for Caesar Cipher.
Do not advance in use of the key for non-alphabetic characters in the plaintext. So for vig_encrypt('Hi Mom!', 'LEMON'), the H is encrypted according to the L from the key, the i (after conversion to I) is encrypted according to the E in the key, and the M in the plaintext is encrypted according to the M in the key (rather than according to the O in the key).
One check on your work: vig_encrypt('ATTACKATDAWN', 'LEMON') should return the string LXFOPVEFRNHR; another is that vig_encrypt('Hi Mom!', 'LEMON') should return the string SM YCZ!