Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribedimage text in transcribed

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

3 How supply and demand together determine market equilibrium.

Answered: 1 week ago

Question

1 What demand is and what affects it.

Answered: 1 week ago