Question

In: Computer Science

In C++ Write a program that contains a function, encrypt(Cypher) that encrypts the below text and...

In C++

Write a program that contains a function, encrypt(Cypher) that encrypts the below text and a second function, decrypt(Cypher),  that decrypts the encrypted message back to normal.  Cypher is the string which contain the plain or cypher texts.  Demonstrate that the encrypted message that you created is correctly decrypted.  For this problem you need to input “All Gaul is …” into a string Cypher.  

Julius Caesar was one of the earliest persons to employ cryptology in history.  All his correspondence from his campaigns to Rome were always encrypted by a very simple method, namely: every letter in his correspondence was transliterated to the next letter in the alphabet. I will provide you with the Introduction to his “Gallic Wars” book:

“All Gaul is divided into three parts, one of which the Belgae inhabit, the Aquitani another, those who in their own language are called Celts, in our Gauls, the third. Among the Helvetii, Orgetorix was by far the most distinguished and wealthy”

Solutions

Expert Solution

Program code:

#include<iostream>
using namespace std;

string Cypher;     //Declaring a string Cypher
int i=0;

string encrypt(string Cypher)      //Function to encrypt the string
{
    while(Cypher[i]!='\0')            //Iterates till the last character of string
    {
        Cypher[i]=Cypher[i]+1;      //Encrypting every character to the next character of alphabet.
        i++;                      
    }
    return Cypher;        //Returns encrypted string
}


string decrypt(string Cypher)   //Function to decrypt the string
{
    while(Cypher[i]!='\0')             //Iterates till the last character of string
    {
         Cypher[i]=Cypher[i]-1;     //Decrypting every character to the previous character of alphabet.
         i=i+1;
    }
    return Cypher;        //Returns decrypted string
}


int main()
{
    Cypher="All Gaul is divided into three parts, one of which the Belgae inhabit, the Aquitani another, those who in their own language are called Celts, in our Gauls, the third. Among the Helvetii, Orgetorix was by far the most distinguished and wealthy";    //Initializing string Cypher with the given string
    cout << "\nEncrypted String is:\n\n" << encrypt(Cypher);    //Printing encrypted string
    cout << "\n\nDecrypted String is:\n\n" << decrypt(Cypher);    //Printing decrypted string
}


Output:

NOTE:

I have provided needed information.

If you feel any difficulty in understanding it,feel free to comment.

If you are satisfied with the answer,please upvote.

Thankyou...


Related Solutions

In this assignment you will write a program that encrypts a text file.  You will use the...
In this assignment you will write a program that encrypts a text file.  You will use the following encryption scheme. Ask the user for the name of the original file. Ask the user for the name of the output file. Ask the user for the encryption key, n. Read n2 characters from the file into the n rows and n columns of a 2-dimensional array. Transpose the array.  (Exchange the rows and columns.) Write the characters from the array to an output...
Write a complete C program that read the text below and save the text in a...
Write a complete C program that read the text below and save the text in a new file "second.txt" with the same text written in all uppercase. "Beedle the Bard was an English wizard and author of wizarding fairytales. Beedle was born in Yorkshire, England. At some point in his life he wrote The Tales of Beedle the Bard . The only known image of Beedle is a woodcut that shows him with a "luxuriant" beard. Beedle wrote in ancient...
how to write program in java for encrypt and decrypt input text using DH algorithm
how to write program in java for encrypt and decrypt input text using DH algorithm
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
Desc: Encrypts or decrypts a file. Input: The user supplies the character '1' to encrypt, or...
Desc: Encrypts or decrypts a file. Input: The user supplies the character '1' to encrypt, or '2' to decrypt via the keyboard.   The user also supplies the name of the source file via the keyboard.   Output: If the user wants to encrypt, the text in input file is encrypted and the encrypted text is stored in "encrypted.txt". The original file is not changed. If the user wants to decrypt, the text in input file is decrypted and the decrypted text...
Using C++, write a code that this program always stores text file output into a text...
Using C++, write a code that this program always stores text file output into a text file named "clean.txt". -The program should read one character at a time from "someNumbers.txt", and do the following. -If it is a letter, print that letter to the screen, AND also store it in the text file. All letters should be converted to lowercase beforehand. -If it is a number, print that number to screen, but do NOT store it in the text file....
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text....
A, B:    Design and Implement a C# windows form application to encrypt and decrypt text. The application use to receive a string and display another encrypted string. The application also decrypt the encrypted string. The approach for encryption/decryption is simple one i.e. to encrypt we will add 1 to each character, so that "hello" would become "ifmmp", and to decrypt we would subtract 1 from each character.    C:   Test and evaluate application by applying different strings.      ...
Write a program that contains a function that takes in three arguments and then calculates the...
Write a program that contains a function that takes in three arguments and then calculates the cost of an order. The output can be either returned to the program or as a side effect. 1. Ask the user via prompt for the products name, price, and quantity that you want to order. 2. Send these values into the function. 3. Check the input to make sure the user entered all of the values. If they did not, or they used...
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt...
Write a program that contains 2 functions. Program will call a function named calc_commission that prompt the user to enter the sales amount and computes and prints with a description the commission paid to salesperson as follows: 10% for sales amount less than $2,000.00, 15% for sales amount less than $10,000.00 and 20% for sales amount less than $20,000.00, then function calc_commission calls another function name assign_base_salary() to ask the user to enter each of 5 salesperson’s base salary ,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT