Question: Please Help Me With Task #4 As I Have Already Done Task #1: #include #include #include using namespace std; // Get the Ciphered Text string

Please Help Me With Task #4 As I Have Already Done Task #1:

Please Help Me With Task #4 As I Have Already Done Task#1: #include #include #include using namespace std; // Get the Ciphered Text

#include

#include

#include

using namespace std;

// Get the Ciphered Text

string encrypt(string str, int);

// Decrypt the Cipher Text

string decrypt(string str, int);

int main() {

printf("Enter shift +/-26:");

int n;

cin>>n;

printf("Enter plaintext message (A-Z only, no spaces): ");

string str;

cin>>str;

// Get the Ciphered text

string cipher = encrypt(str,n);

// Decrypt the Cipher Text

string plaintext = decrypt(cipher,-n);

cout

return 0;

}

// Get the Cipher Text

string encrypt(string str,int n) {

int i;

for(i=0;i

// Get the Ascii Code

int ascii=(int)str[i];

ascii=ascii+n;

if(ascii

ascii=91-(65-ascii);

else if(ascii>90)

ascii=64+(ascii-90);

// Update the Character With the Ciphered Text

str[i]=(char)ascii;

}

return str;

}

// Decrypt the Cipher Text

string decrypt(string str, int n) {

int i;

for(i=0;i

// Get the Ascii Code

int ascii=(int)str[i];

ascii=ascii+n;

if(ascii

ascii=91-(65-ascii);

else if(ascii>90)

ascii=64+(ascii-90);

// Update the Character With the Ciphered Text

str[i]=(char)ascii;

}

return str;

}

Task 1 (Weightage 25%) You are asked to write a program that takes a shift value between +/- 26 and a plaintext message (no spaces) and returns the corresponding ciphertext. The program should also implement a decryption routine that reconstructs the original plaintext from the ciphertext. Example usage $ ./ caesar Enter shift +/- 26: -3 Enter plaintext message (A-Z only, no spaces): THE ciphertext: QEB plaintext: THE or $ ./ caesar Enter shift +/- 26: 1 Enter plaintext message (A-Z only, no spaces): Zzz ciphertext: AAA plaintext: zzz We assume that the user message only consists of uppercase English alphabet (A-Z). Task 4 (Weightage 25%) Thus far the program only handles capital letters A-z. Now add support for small letters a-z and digits 0-9 Assume that for letters shift values are between-26 and +26 and for digits shift values are between 10 and +10. This program will support both input and output files and io redirection Usage Say file in.txt contains Good dog 2 Then the following command create an output file as seen below $ ./caesar -e 1 3 in.txt output.txt Contents of output.txt file Hppe eph 5 Similarly, we can decrypt output.txt to create original.txt as follows $ ./caesar -d 1 3 in.txt original.txt The contents of the original.txt are Good dog 2 Program help $ ./caesar -[eld] [file-input] [file-ouput] '-erefers to encryption -d' refers to decryption shift-letter a value between -26 and +26 shift-digit' a value between -10 and +10 'file-input name of the input file. If none specified, read from 'stdin 'file-output" name of the output file. If none specified, write to 'stdout

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!