Problem 6
Background: One field of computer science is cryptography, which studies the techniques for secure communication in the presence of third parties, adversaries. In classical symmetric-key algorithms, both sender and receiver use the same cryptographic key to encrypt the text. The encrypted text will then be sent to the other parties. The other party will use the same key to decrypt the text to get the original message. This scheme works under the assumption that if the
adversary does not know the private key, he would not be able to decrypt the message even if he intercept the encrypted message.
In symmetric-key algorithms, Caesar Cipher is one of the oldest ciphers in human history, as you can probably tell from its name (Caesar). In Caesar cipher, each character in the text will be shifts a given number of places (key) down the alphabets. For example, for a cipher key: 2 , the character 'a' will be shifted to 'c', and 'z' will be shifted to 'b'.
Question: Write a function caesarCipher which takes a cryptographic key n and a message in character strings from the user and output the corresponding encrypted text according to the ASCII code. The input will be alphabet and numbers. Numbers also follow rotation cipher when meeting the end. Message only consists of alphabetic and numeric characters.
Example:
Input: caesarCipher(2, 'ThisisVZ109')
Output: 'VjkukuXB321'