Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE: Does not have to be completed on the linux server. Can be written in any C++ compiler Project 2 - Encryption Important: If you

NOTE: Does not have to be completed on the linux server. Can be written in any C++ compiler

Project 2 - Encryption

Important: If you get stuck in an infinite loop (you go to run your program and it freezes or starts scrolling the screen), press CTRL + C (hold CTRL and press C), and it will stop your program from running (it may take a few seconds). DO NOT simply shut down the window. This may leave your program running indefinitely on the server.

Objectives:

For this project, you will write a short program in C++ that will encrypt a word or sentence, known as the plaintext, which will be supplied by the user. If you reach the later steps in the project, your input may also consist of a key, also supplied by the user.

You may assume that the plaintext is entirely in lowercase letters, and contains no punctuation. For plaintext containing multiple words, there will be spaces.

Your output should contain the output from each of the steps 1-4 that you've completed, each with an appropriate message and on a new line. All should use the same plaintext, which you should only prompt for once.

1) Echo the input: First, you should make sure you can write a program and have it compile and run, take input and give output. So to start you should just echo the input. This means you should prompt the user for the plaintext, read it in and then print it back out, with a message such as "this is the plaintext you entered:". [3 points for writing a working program, echoing the input and submitting the program on the CS dept Linux network] 2) Simple Substitution Cipher: One of the earliest and simplest types of ciphers was called a "simple substitution cipher". And one of the simplest of these simple substitution ciphers was the cipher where each letter is replaced by the next letter in the alphabet. For example, 'a' is replaced by 'b', 'b' is replaced by 'c', and so on, until you get to 'z', which is replaced by 'a'. Have your program take a single word as input and perform this simple substitution cipher on it, then print out the encrypted text (also known as ciphertext) [3 points]

Hint: you can add a numerical value to a character. For example, if you add 1 to the character 'a', it becomes 'b'. If you add 2 to 'a', it becomes 'c', and so on and so forth. Be careful with 'z' - it needs a special case.

3) Polyalphabetic (or Block) Cipher: Simple (or monoalphabetic) substitution ciphers can be easily broken by letter frequency analysis, leading to the development of polyalphabetic ciphers, which are the precursors to block ciphers, which are the basis for modern cryptography.

You'll implement a simple block cipher that will work as follows: instead of simply "increasing" each letter by 1, imagine the plaintext being divided into blocks of 8 characters. Then, in each block, you'll increase the first letter by 1, the second letter by 2, the third letter by 3, until you reach the 8th letter, which you'll increase by 8. The 9th letter of the plaintext will start the 2nd block, thus the 9th letter will be increased by 1 again, the 10th letter by 2, and so on and so forth.

Example: plaintext: c r y p t o g r a p h y you add: 1 2 3 4 5 6 7 8 1 2 3 4 ciphertext: d t b t y u n z b r k c

[4 points for getting this to work in all cases. 2 points for getting this to work for characters that don't don't go past 'z'.]

Hint: to get this to "wrap around" from 'z' to 'a', it will require more than just a special case. You must figure out and implement a general rule for what to do when the result of your substitution causes the value of your character to exceed 'z'. Being able to treat characters as their integer values in mathematical expressions may help you here - for example, you can compare characters with < and > (less than and greater than). You can compare 2 characters or you can compare a character's ASCII value to an integer. If you're really stuck, you may want to look at an ASCII chart.

Extra Credit:

You may complete any (or all) of these you're able to, after completing step 3. [1 additional point for the first one you complete]

4) Variable-Length Block Cipher with Key: For this step, you'll need the user to enter a key. This key will be a word (no spaces) consisting of only lowercase letters. Then, you'll implement a block cipher as in step 3, except the length of the key will be the size of the block, and you'll add the alphabetic position of each letter in the key to each letter in the block. [1 point]

For example, if your key is "crypto", you'll add: 3 to the first letter of the plaintext (c=3) 18 to the 2nd letter of the plaintext (r=18) 25 to the 3rd letter of the plaintext (y=25) 16 to the 4th letter of the plaintext (p=16) 20 to the 5th letter of the plaintext (t=20) 15 to the 6th letter of the plaintext (o=15) 3 to the 7th letter of the plaintext, because we're back to the "c" at the beginning of "crypto".

5) Allow the Plaintext to be a Sentence: Treat spaces as the 27th letter of the alphabet, so that your plaintext can be a sentence (or even a paragraph without punctuation). Encrypt spaces as you would any other character, but note that the "space" character will need to be treated as a special case, since it is not next to the lowercase letters in ASCII. Note that this will require altering your code from steps 2, 3, and 4 if you did it. [1 point]

Hint: cin by itself will only read a string until the first space. To read in a sentence, use getline(cin,stringname);

6) Use Command Line Arguments: Allow the user to enter the input (the plaintext, and the key if applicable) through his choice of a command line argument or being prompted for input. The way that this will work is that if the user enters a command line argument, that will be used as the input. If he does not, he will be asked to input his plaintext (and key if applicable) as normal. An example of using command line arguments is included in my "readings and code samples" on Blackboard.

[1 point to get it working on an input of a one-word plaintext (and key if applicable), 2 points to get it working on a sentence of plaintext]

Note that having a sentence as your plaintext in a command line argument will require using techniques a fair bit beyond the scope of this course, so you can use a command line argument for just a one-word plaintext while allowing a sentence of plaintext to be entered via prompting the user.

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

Modern Database Management

Authors: Heikki Topi, Jeffrey A Hoffer, Ramesh Venkataraman

13th Edition

0134773659, 978-0134773650

More Books

Students also viewed these Databases questions

Question

=+Why does the brand want to advertise?

Answered: 1 week ago

Question

18. If you have power, then people will dislike and fear you.

Answered: 1 week ago