In: Computer Science
use C++
You will implement the following encryption and decryption functions/programs for the Caesar cipher. Provide the following inputs and outputs for each function/program:
EncryptCaesar
Two inputs:
A string of the plaintext to encrypt
A key (a number)
▪ For the Caesar cipher: This will indicate how many characters to shift (e.g. for a key=3, A=>D, B=>E, ..., X=>A, Y=>B, Z=>C). Note that the shift is circular.
One output:
◦ A string of the ciphertext or codeword
DecryptCaesar
Two inputs:
◦ A string of the ciphertext to decrypt ◦ The key (a number)
One output:
◦ A string of the plaintext
Obviously, for this assignment to be successful, the decryption function/program must decrypt the original message which was encrypted by the encryption function/program. Or, for a plaintext P and an encryption function E() and a decryption function D(), P = D( E(P, Key), Key)
//required libraries are included
#include <iostream>
#include <algorithm>
#include <string.h>
#include <map>
using namespace std;
//start of main function
int main()
{
//declarations and initialisations
string plain_text,cipher_text;
int key_p,key_c,size_plain_text, size_cipher_text;
int value1,value2,j,i;
char value_char;
//reference list of characters
char
my_list[]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
cout<<"Enter a Plain String to
Encrypt-"<<endl;
cin>>plain_text;
cout<<"Enter the Key for
Encryption-"<<endl;
cin>>key_p;
cout<<"Enter a Cipher String to
Decrypt-"<<endl;
cin>>cipher_text;
cout<<"Enter the Key for
Decryption-"<<endl;
cin>>key_c;
//size of texts are found here
size_plain_text=plain_text.size();
size_cipher_text=cipher_text.size();
char
encrypted_text[size_plain_text],decrypted_text[size_cipher_text];
//Encryption Loop
for(i=0;i<size_plain_text;i++)
{
//Caesar Encryption Functional Statements
value1=plain_text[i];
value1=value1-65;
value1=value1+key_p;
value1=value1%26;
encrypted_text[i]=my_list[value1];
}
//Decryption Loop
for(j=0;j<size_cipher_text;j++)
{
//Caesar Decryption Functional Statements
value2=cipher_text[j];
value2=value2-65;
value2=value2-key_p;
if(value2<0)
{
value2=26+value2;
}
decrypted_text[j]=my_list[value2];
}
cout<<"Encrypted Text is:
"<<encrypted_text<<endl;
cout<<"Decrypted Text is:
"<<decrypted_text<<endl;
return 0;
}