Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello! I got a task in C++ I need help with: The program first asks for the encryption key with which to encrypt the text

Hello! I got a task in C++ I need help with:

The program first asks for the encryption key with which to encrypt the text with the prompt: "Enter the Encryption key: " and then reads the entered string as the encryption key.

Next, the program checks the validity of the entered string as an encryption key. The following checks are performed on the string in the following order:

The string must be 26 characters long. If not, an error message is printed: "Error! The Encryption key must contain 26 characters." The character string may only contain English lowercase letters, i.e. the characters 'a' - 'z'. If the string contains something else, an error message is printed: "Error! The Encryption key must contain only lower case characters." The string must contain all English lowercase letters. If not, an error message is printed: "Error! The Encryption key must contain all alphabets a-z." The execution of the program ends with the return value EXIT_FAILURE immediately after printing the error message, i.e. the program can print only one of the error messages in one run.

When the program has read and checked the key, it asks the user for the word that the user wants to encrypt with the prompt: "Enter the text to be encrypted: " and then reads one string as the text to be encrypted.

The character string to be encrypted is checked to ensure that it contains only English lowercase letters. If the string contains something else, an error message is printed: "Error! The text to be encrypted must contain only lower case characters." and program execution is terminated with the return value EXIT_FAILURE.

The program encrypts the letters using a simple replacement method, the replacements for the letters are obtained from the encryption key. The encryption key is interpreted in such a way that its first character corresponds to the a of the text to be encrypted, the second to b and the last, i.e. the 26th character, corresponds to the letter z.

For example, the text encrypted with the encryption key abcdefghijklmnopqrstuvwxyz looks exactly the same as the original, because the letter a is replaced by the letter a, b is replaced by b, etc. With the encryption key abcdefghijklmnopqrstuvwzyx, the encryption would change all x letters to z letters and z letters to x letters without changing the other letters.

There was another question like this but I couldn't get the answer provided to work so I am hoping you'd help me out here. Thank you!

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 2 Lnai 9285

Authors: Annalisa Appice ,Pedro Pereira Rodrigues ,Vitor Santos Costa ,Joao Gama ,Alipio Jorge ,Carlos Soares

1st Edition

3319235249, 978-3319235240

More Books

Students also viewed these Databases questions

Question

How do they adapt when those messages are challenged?

Answered: 1 week ago