Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a C++ program that allows the user to enter a text, such as the one seen

ID: 3603024 • Letter: C

Question

Create a C++ program that allows the user to enter a text, such as the one seen in the picture, and displays the decrypted message. The user should also be able to enter the "n" value of the shift, dictating the how many places the Caeser Cipher shifts the letters in the alphabet. The program must be able to compute lowercase as well as uppercase letters and symbols, which are not encrypted. If possible, use the equation seen at the top of the picture.

The Caesar Cipher can be represented using modular arithmetic as follows. Enc(x) (x + n) mod 26 This means that the encryption of a letter x is equal to a right shift of x by n letters. The result of the process is then taken under modulo division, meaning that if a letter is shifted past the end of the alphabet, it wraps around to the beginning Now, you are given below a cipher text encrypted using Caesar Cipher. "Fhewhqccydw qdt shofjewhqfxo ghu vkd. Oek sd tushofj jxyi cuiiqwu kiydw rhkju vehsu qjjqsa. Sxusai gbb feiiyrbu auoi kdjyb jxu sehhusj edu yi vekdt." Where the period () and comma () symbols are not encrypted. Write a program to decrypt this message by exhaustively search over all possible 26 keys.

Explanation / Answer

Hi
here is the code with comments to help you understand,

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
// string x="Fhewhqccydw qdt shofjewhqfxo qhu vkd. Oek sqd tushofj jxyi cuiiqwu kiydw rhkju vehsu qjjqsa. Sxusai qbb feiiyrbu auoi kdjyb jxu sehhusj edu yi vekdt.";
string x;
cout<<"enter string"<<endl;
getline(cin, x);
cout<<x;
int n;
cout<<"enter the n value for shift";
cin>>n;
cout<<n<<endl;
  
for(int j=0;j<x.length();j++)//looping through each char of string
{
if(x[j]!='.' && x[j]!=' ')//if its not space of .
{
int temp=(((int)x[j]-n));//taking subtractions of the shift denoted by i for each iteration
char w = static_cast<char>(temp);//covert ASCII back to char
cout<<w;
}
else
{
  
cout<<x[j];
}
}

return 0;
}
Thumbs up if this was helpful, otherwise let me know in comments