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

Given this empty shell code I need help with this problem. Language is C++ pleas

ID: 3723718 • Letter: G

Question

Given this empty shell code I need help with this problem. Language is C++ please, thank you.
// Place your information here #include <iostream> int main() { return 0; } Part B: Rot13 Encoding/decoding (rot13.cpp) - Milestone Part B Objective The goal of part B is to create a program to encode files and strings using the rot13 encoding method Information about the rot13 method can be found at Implement the rot13 algorithm using functions, strings and file I/O. You program should use at least 3 to 4 functions. It should be able to read in a text file from a specified filename, encode using rot13, and write it to a specified file. It should be able to decrypt it in the same way. The starter code for rot13 is rot13.cpp which is mostly an empty shell. You will need to provide the file I/O and the functions that implements the rot13 algorithm. Note: rot13 is very specific version of the Caesar cipher. The rot13 algorithm just simply rotates each individual alphabetic character by 13 characters. It leaves the numbers, punctuation, etc alone. To "encrypt" you just rotate each character by 13 characters. To "decrypt" you just rotate (in either direction) the characters by 13 as well. Please preserve the case of the rotated letter You may want to convert all lowercase to uppercase characters before performing math on them to avoid overflows. You will want to convert them back to lowercase when done.

Explanation / Answer


#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
class Rot13Solutution{
public:
template <typename Iter>
void rot13Impl(Iter begin, const Iter& end) {
while (begin != end) {
char& c = *begin;
if (c >= 'a' && c <= 'm') {
c += 13;
} else if (c >= 'n' && c <= 'z') {
c -= 13;
} else if (c >= 'A' && c <= 'M') {
c += 13;
} else if (c >= 'N' && c <= 'Z') {
c -= 13;
}
++begin;
}
}
};
int main () {
//This is for encrypting data and store it in encrypted file
Rot13Solutution sol;
string line;
ifstream myfile ("example.txt");
ofstream myoutfile ("encrypt.txt");
if (myfile.is_open())
{
while ( getline (myfile,line) )
{
int n = line.length();

// declaring character array
char str[n+1];

// copying the contents of the string to char array
strcpy(str, line.c_str());
sol.rot13Impl(str,str + strlen(str)) ;
if(myoutfile.is_open())
{
myoutfile<<str;
myoutfile.close();
}
else cout << "Unable to open output file";
//cout << str << ' ';
}
myfile.close();
}
else cout << "Unable to open input file";
  
cout << "Your file data is being encrypted by ROT13 algorithm and stored in encypt.txt" << ' ';
cout << "-----------------------------------------------------------"<<' ';
//This is for Decrypting data and store it in Decrypted file
string dline;
ifstream myEncryptedfile ("encrypt.txt");
ofstream myDecryptedfile ("decrypt.txt");//decrypt file is same as the orginal file i.e example.txt
if (myEncryptedfile.is_open())
{
while ( getline (myEncryptedfile,dline) )
{
int n = dline.length();

char str[n+1];
strcpy(str, dline.c_str());
sol.rot13Impl(str,str + strlen(str)) ;
if(myDecryptedfile.is_open())
{
myDecryptedfile<<str;
myDecryptedfile.close();
}
else cout << "Unable to open output decrypted(original) file";
}
myEncryptedfile.close();
}
else cout << "Unable to open file to be decrypted";
cout << "Your file data is being decrypted by ROT13 algorithm and stored in decrypt.txt" << ' ';
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote