In: Computer Science
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”
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...