Menu

[solved]-Want Exactly Like Output Simple Explained Way Two Thousand Years Codemakers Fought Preserv Q39083400

I want it exactly like the output and in simpleexplained way

“For two thousand years, codemakers have fought to preservesecrets while codebreakers have tried their best to reveal them.” -taken from Code Book, The Evolution of Secrecy from Mary, Queen ofScots to Quantum Cryptography by Simon Singh.

The idea for this machine problem came from this book.You willencrypt and decrypt some messages using a simplified version of acode in the book. The convention in cryptography is to write theplain text in lower case letters and the encrypted text in uppercase letters. We will follow this convention for this machineproblem. We will only encrypt/decrypt letters. Any other characterwill be left as is (i.e. 1 2 3 . , etc).

For simplicity we will exclude the letter ‘z’ from the alphabet(see below). The method of encryption used here is a simplesubstitution cipher that depends on the sender and receiver of themessage agreeing on a keyword, which is usually just one word thatwill be easy to remember. Thus the key for decrypting the messagewill not have to be written down and is less likely to fall intoenemy hands!

First, the program must read in a keyword, which will be allcapital letters. The letters of the keyword must be inserted in theorder in which they occur into a 5×5 two dimensional array by rows,but if a letter is repeated in the keyword it is only used once inthe two-dimensional array. Then the array is filled up with theremaining letters of the alphabet in order (excluding the ‘Z’).e.g.if the keyword was PHENOMENON the array would contain thefollowing:

0 1 2 3 4 0 PHENO 1 MABCD 2 F G I J K 3 LQRST 4 U V W X Y

Next, the program will read in a series of lines containingeither messages to encrypt or decrypt.

A plain text message will be encrypted as follows:

Each letter in the message will be found in the table, and therow and column will be noted: e.g. ‘g’ (when converted to uppercase) occurs at row 2, column 1 in the above array. (Remember thatindexes start at 0 in C++).

It will then be encrypted by reversing the row and columnvalues, so that ‘g’ will become the character at row 1, column 2,i.e. ‘B’ in the encrypted message.

Thus if the message was “good luck” it will be encrypted as”BUUV NOQW” Spaces between words will be maintained exactly as theyappear in the message.

A message that is already encrypted can be decrypted usingexactly the same algorithm – the only difference is that theincoming message will be in upper case and the decrypted messagewill be in lower case.

You should process a file that contains the following:

HAPPINESS
D EVDEUOA XC GCERVLEWQ, FESS BC EUV OCWWAOX XLC HNUVRAVVCWWERS
E hello there
D HAWWC XHARA
E attack at dawn
D IAAX IA NUVAR HEIIARSIMXH GRMVBA
E the meeting is in san francisco
D XHMS MUPCRIEXMCU MS AUORYFXAV NSMUB XHA QAYLCRV HEFFMUASS
D XHA EUSLAR XC XHA PMRSX KNASXMCU CU XHA PMUEW IEY GA XRNA CR MXIEY GA PEWSA
E the answer to the first question on the final may be true or itmay be false
D OCUBREXNWEXMCUS YCN IEVA MX XHRCNBH XHMS IEOHMUA FRCGWAI
E advance to boardwalk, pass go and collect two hundreddollars
E make my day
E zorro is back (in town)
E you ain’t nothing but a hound dog
E one day a computer will weigh less than a ton — popularmechanics 1948
E no computer will ever need more than 640k of memory — bill gatesin the mid eighties
D YCN EMUX UCXHMUB GNX E HCNUV VCB
D CUA VEY E OCIFNXAR LMWW LAMBH WASS XHEU E XCU — FCFNWERIAOHEUMOS 1948
D UC OCIFNXAR LMWW ADAR UAAV ICRA XHEU 640Q CP IAICRY — GMWW BEXASMU XHA IMV AMB HXMAS
E the attack will start in $”population” minutes

This file has the keyword on the first line, then a series oflines beginning with ‘E’ (for encrypt) or ‘D’ (for decrypt), thenexactly one space, and then the message to be either encrypted ordecrypted. The program should read these lines until it comes tothe end of the file.

The output should echo all the data, print out the twodimensional array as above, and print out the messages and theirencoded equivalents (in either upper case (encrypting output) orlower case(decrypting output)).

So the first few lines of output on the above program would besomething like:

keyword is HAPPINESS

0 1 2 3 4
———————
0| H | A | P | I | N |
———————
1| E | S | B | C | D |
———————
2| F | G | J | K | L |
———————
3| M | O | Q | R | T |
———————
4| U | V | W | X | Y |
———————
****************************************
EVDEUOA XC GCERVLEWQ, FESS BC EUV OCWWAOX XLC HNUVRAV VCWWERS
decrypts to:
advance to boardwalk, pass go and collect two hundred dollars
****************************************
hello there
encrypts to
HAWWC XHARA
****************************************
HAWWC XHARA
decrypts to:
hello there
****************************************
attack at dawn
encrypts to
EXXEOQ EX VELU
****************************************
IAAX IA NUVAR HEIIARSIMXH GRMVBA
decrypts to:
meet me under hammersmith bridge

…….

Have fun!!

Requirements:
1.) Break up the problem into smaller modules and get each oneworking before going on to the next. E.g. concentrate first on howto build the two-dimensional array from the keyword.
2.) Make sure you print out your 5×5 table using the key read fromthe file.

Hint:
C++ provides 2 useful functions called toupper and tolower.Checkout the following code to see how they get used:

char c;
c = tolower(‘C’);
cout << c << endl;
c = toupper(‘d’);
cout << c << endl;

0 1 2 3 4 0 PHENO 1 MABCD 2 F G I J K 3 LQRST 4 U V W X Y Show transcribed image text 0 1 2 3 4 0 PHENO 1 MABCD 2 F G I J K 3 LQRST 4 U V W X Y

Expert Answer


Answer to I want it exactly like the output and in simple explained way “For two thousand years, codemakers have fought to preserv… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *