Create a function that can encrypt and decrypt a text message using a Caesar encryption scheme.

Caesar(string, key)

This should utilize the simple Caesar scheme to shift the alphabetic/numeric values by the key specified. Be sure to incorporate the printable range of ASCII characters (i.e. Decimal 32 to 126).

The function should receive a string and a numeric key. This function shifts the characters in the text message by the designated key value and returns the altered printable text message.

To encrypt a message call the method with plaintext and pass the cypher key. To decrypt a message call the method with the cypher text and the inverse key (e.g. if 2 was used to encrypt, then -2 would be used to decrypt).

NOTE: If you shift a character out of the printable ASCII range (i.e. an ASCII value less than 32 or greater than 126) you’ll need to “wrap” the character to the beginning or end of the ASCII range:

  • If the shifted value is < 32 then you’ll need to “wrap” it to the upper end of the ASCII range by adding 95.
  • If the shifted value is > 126 then you’ll need to wrap it to the lower end of the ASCII range by subtracting 95.
Subscribe For Latest Updates
Let us notify you each time there is a new assignment, book recommendation, assignment resource, or free essay and updates