Question: In cryptography, a cipher is an algorithm for encrypting and decrypting some given message through a series of well-defined steps. Commonly called codes, there are
In cryptography, a cipher is an algorithm for encrypting and decrypting some given message through a series of well-defined steps. Commonly called codes, there are various types of ciphers ranging from fairly simple to complex. One of the most widely known encryption schemes is called a Caesar Cipher or Shift Cipher. The Caesar Cipher encrypts a letter by substituting for it with another letter that is a fixed distance, or shift, away in the alphabet. For example, to use a shift of +3 in a Caesar Cipher, we would substitute the letter D for A, E for B, and so on, as illustrated below.

As you can see in the image above, each letter is being replaced with the letter 3 positions forward in the alphabet. For this problem you will be creating a function which performs both encryption and decryption of a message using this scheme. Write a function caesarCipher which will either encrypt a message or decrypt a coded message using a Caesar Cipher.
Your function MUST be named caesarCipher
Your function takes three input arguments in this order: a string message, an int key, and a bool flag
Your function must return the resulting string from the encoding or decoding algorithm. It should NOT print the resulting string using cout.
message will be a string in all capital letters with spaces. Unencoded messages will be strings such as I LIKE CHOCOLATE or HELLO WORLD, and encoded messages will be strings such as L OLNH FKRFRODWH or KHOOR ZRUOG.
key will be an integer that specifies how many positions in the alphabet are being shifted in the encoding or decoding process. A valid key must be between 0 and 25. If your function is given a value outside of this range, it should return ERROR;
flag will be a boolean variable that controls whether your function will be encrypting or decrypting the given message. A value of true will mean your function is encoding the given message, and a value of false will mean your function is decoding it.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
