Question: I have this program for Caeser chipper below bold . I need Task 2 to be added to the program as another function. PLEASE, PLEASE!
I have this program for Caeser chipper below bold. I need Task 2 to be added to the program as another function.
PLEASE, PLEASE! Answer the question only if you're sure about what you're doing.
Thank you.
TASK 2:
In the Caesar cipher, each letter is always shifted by the same value. What if we shifted each letter by a different value? A cipher known as the Vigenere cipher consists of several Caesar ciphers in sequence with different shift values. For example, we might shift the first letter of the plaintext to the right by five, the second by 17, etc. The sequence is defined by a keyword where each letter defines the shift value. If a letter in the keyword is the nth letter in the alphabet, then each ciphertext letter will be the corresponding plaintext letter shifted to the right by n-1. For example, suppose that the plaintext to be encrypted is: Hello, world! ...and the person sending the message chooses the keyword "cake". The first letter of the keyword is 'c', and 'c' is the third letter of the alphabet. That means we shift the first letter of the plaintext to the right by 3-1 = 2, which makes the first letter of the ciphertext 'J'. Then repeat for the remaining letters. If we reach the end of the keyword, go back and use the first letter of the keyword. Following these steps, the resulting ciphertext is: Jevpq, wyvnd! Write a C++ function to implement the Vigenere cipher. You may make your own prototype though it should return the encrypted string as above. Again, your function should preserve case, and any non-alphabetic characters should be left unchanged.
#include
using namespace std;
string encryptCaesar(string orig, int rshift){
string output = "";
for (int i=0;i
{
if(isalpha(orig[i])){
if (isupper(orig[i]))
output += char(int(orig[i]+rshift-65)%26 +65);
else
output += char(int(orig[i]+rshift-97)%26 +97);
} else
output += orig[i];
}
return output;
}
int main()
{
string text;
cout<<"Enter the text: ";
getline(cin,text);
cout<
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
