ROT13 rotate by 13 places is a simple letter substitution ci
ROT13 (rotate by 13 places) is a simple letter substitution cipher that is an example of a Caesar cipher used by Julius Caesar. ROT13 replaces a letter with the letter 13 letters after it in the alphabet. (A==>N, B==>O, C==>P, etc...) So, the translation of the word COMPUTER using ROT13 would be PBZCHGRE.
Write a C++ program that asks the user for the name of an input file and translates the contents of that file using ROT13. Your program should also save the results of the translation into another file with a \".rot13\" file extension.
Submit:
Fully documented and compilable source code
Documentation should include:
Pseudocode
Top comment block (The name of the program, The name of the programmer, The date of the program, and A brief description of the purpose of the program)
Function comments (Description, pre and post conditions)
Internal comments for all functions
Solution
Pseudocode :
1. Input the string to encrypt
2. Encrypt the string by using ROT13 ceaser cipher method
3. If the given string is an alpha string and If tolower(string) –a is lesser than 14 , use the + 13 key to append
4. If tolower(string) –a is greater than 14 , use the - 13 key to append
5. Output the encrypted result.
Program :
#include <cctype>
#include <iostream>
 #include <string>
 
 using namespace std;
 
 string ROT13(string msg)
 {
 string encrypted;
 for (size_t i = 0; i < msg.size(); ++i) {
 if (isalpha(msg[i])) {
 if ((tolower(msg[i]) - \'a\') < 14)
 encrypted.append(1, msg[i] + 13);
 else
 encrypted.append(1, msg[i] - 13);
 } else {
 encrypted.append(1, msg[i]);
 }
 }
 return encrypted;
 }
 
 int main()
 {
 string msg;
 string s;
 cout << \"Enter the message: \" << flush;
 getline(cin, msg);
 cout << \"Encryted message : \" << ROT13(msg) << endl;
 
 }
Output :
Enter the message: abcdefgh
Encryted Text : nopqrstu


