Question
Need this in c++// Please explain your code (Change up the code please) #include #include using namespace std; // get the ciphered text string encryption(string
Need this in c++// Please explain your code
(Change up the code please)
#include
#include
using namespace std;
// get the ciphered text
string encryption(string strng, int);
// decrypt the cipher text
string decryption(string strng, int);
int main()
{
cout
int n;
cin>>n;
cout
string strng;
//gets input
cin>>strng;
// get the ciphered text
string cipher = encryption(strng, n);
// decrypt the cipher text
string plaintext = decryption(cipher, -n);
cout
return 0;
}
// get the ciphered text
string encryption(string strng, int n)
{
int i;
for( i = 0 ; i
{
// get the ascii code convert string to int
int ascii = (int)strng[i];
ascii = ascii + n;
if(ascii
ascii = 91 - ( 65 - ascii );
else if(ascii > 90)
ascii = 64 + (ascii - 90);
// update the character with the ciphered text
strng[i] = (char)ascii;
}
return strng;
}
// decrypt the cipher text
string decryption(string strng, int n)
{
int i;
for( i = 0 ; i
{
// get the ascii code
//changes the ascii into the string
int ascii = (int)strng[i];
ascii = ascii + n;
if(ascii
ascii = 91 - ( 65 - ascii );
else if(ascii > 90)
ascii = 64 + (ascii - 90);
// update the character with the ciphered text
strng[i] = (char)ascii;
}
return strng;
}
You are now to extend the above program to take as inputs files. The program should be able to read a file and encode or decode it as needed For the sake of simplicity, we assume that you only need to change letters [A-Z] in the file. You can safely ignore other letters in the file (i.e., keep those as is.) Encrypting a file to cyphertext Encrypt a file in. txt containing plaintext to a file out.txt containing ciphertext using shiftStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started