Question

In: Computer Science

Write a C++ program performing the rot13 cipher, The code should perform like this: The user...

Write a C++ program performing the rot13 cipher, The code should perform like this:

The user should be able to input any letter or words, or even sentences where once they have inputted the particular word, each letter goes 13 letters ahead, so an 'A' becomes an 'N', a 'C' becomes 'P', and so on. If rot13 cipher is tested a second time, the original plantext should be restored: 'P' becomes 'C', 'N' becomes 'A'. The 13 letters go in a rotation so if we have 'Z', 13 letters ahead of it is 'M'. So using c++ perform the rot13 cipher.

Solutions

Expert Solution

#include <iostream>
#include <string>

using namespace std;

string encrypt_or_decrypt(string str) {
    string ret = "";
    char ch;
    for(int i = 0; i < str.length(); ++i) {
        ch = str[i];
        if(ch >= 'A' && ch <= 'Z') {
            ch = ((ch-'A'+13)%26) + 'A';
        }
        if(ch >= 'a' && ch <= 'z') {
            ch = ((ch-'a'+13)%26) + 'a';
        }
        ret += ch;
    }
    return ret;
}

int main() {
    string str;
    cout << "Enter a sentence: ";
    getline(cin, str);
    string cipher = encrypt_or_decrypt(str);
    cout << "converted to rot13: " << cipher << endl;
    cout << "decrypted to get original  message: " << encrypt_or_decrypt(cipher) << endl;
    return 0;
}


Related Solutions

Write a C++ program performing the rot13 cipher: Basically the code should perform like this: The...
Write a C++ program performing the rot13 cipher: Basically the code should perform like this: The user should be able to input any letter or words, or even sentences where once they have inputted the particular word, each letter goes 13 letters ahead, so an 'A' becomes an 'N', a 'C' becomes 'P', and so on. If the rot13 cipher is applied a second time, the original plantext is restored: 'N' becomes 'A', 'P' becomes 'C'. The 13 letters go...
Write an Java/C program code to perform known-plaintext attack on Permutation Cipher. This program can be...
Write an Java/C program code to perform known-plaintext attack on Permutation Cipher. This program can be used to determine the length of the permutation m and the key permutation.
write a program to perform the following in C Your program should prompt the user to...
write a program to perform the following in C Your program should prompt the user to enter ten words, one at a time, which are to be stored in an array of strings. After all of the words have been entered, the list is to be reordered as necessary to place the words into alphabetical order, regardless of case. Once the list is in alphabetical order, the list should be output to the console in order. The program should execute...
All Code should be written in C: 1. Write a C program which prompts the user...
All Code should be written in C: 1. Write a C program which prompts the user to enter two integer values. Your program should then print out all numbers between 1 and 1000 that are divisible by both of those numbers. 2. Modify your program from question 1 such that the first 1000 numbers that are divisible by both numbers are printed out, instead of numbers up to 1000. 3. Using dynamic memory, allocate memory for an array of 100...
This needs to be a python3 code Write a program that prompts the user like this:...
This needs to be a python3 code Write a program that prompts the user like this: “Currency to convert to U.S. dollars: e = Euros, c= Chinese Yuan, r = Indian Rupees, b = Bitcoin: ”. Then depending on which letter the user enters, the program displays “Amount of Euros/Yuan/Rupees/Bitcoin to convert: ”. (Note: the second prompt should only name the one currency the user asked to convert, not all four currencies.) After the user enters the amount, the program...
*Please write code in C++* Write a program to verify the validity of the user entered...
*Please write code in C++* Write a program to verify the validity of the user entered email address.   if email is valid : output the stating that given email is valid. ex: "The email [email protected] is valid" else : output the statement that the email is invalid and list all the violations ex:  "The email sarahwinchester.com is invalid" * @ symbol * Missing Domain name The program should keep validating emails until user enter 'q' Upload your source code. ex: main.cpp
Write a C Program that uses file handling operations of C language. The Program should perform...
Write a C Program that uses file handling operations of C language. The Program should perform following operations: 1. The program should accept student names and students’ assignment marks from the user. 2. Values accepted from the user should get saved in a .csv file (.csv files are “comma separated value” files, that can be opened with spreadsheet applications like MS-Excel and also with a normal text editor like Notepad). You should be able to open and view this file...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 ( Number 1 should be less than Number 2) 2. calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 2 and 20 (inclusive)...
Write a C++ code to perform the following steps: 1. Ask the user to enter two...
Write a C++ code to perform the following steps: 1. Ask the user to enter two whole numbers number1 and number2 (Number1 should be less than number2) 2. Calculate and print the sum of all even numbers between Number1 and Number2 3. Find and print all even numbers between Number1 and Number2 4. Find and print all odd numbers between Number1 and Number2 5. Calculate and print the numbers and their squares between 1 and 20 (inclusive) 6. Calculate and...
Write a C program/code that prompts the user for a minimum min and a maximum max....
Write a C program/code that prompts the user for a minimum min and a maximum max. Then use these values to print the squares of all even numbers between the min and max variables. For example if the user enters 6 as the minimum and 200 as the maximum, the program/code should print the following. Enter limit on minimum square: 6 Enter limit on maximum square: 200 36 64 100 144 196
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT