Question

C++ Code

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

The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The convention in cryptography is to write the plain text in lower case letters and the encrypted text in upper case letters. We will follow this convention for this machine problem. We will only encrypt/decrypt letters. Any other character will 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 simple substitution cipher that depends on the sender and receiver of the message agreeing on a keyword, which is usually just one word that will be easy to remember. Thus the key for decrypting the message will not have to be written down and is less likely to fall into enemy hands!

First, the program must read in a keyword, which will be all capital letters. The letters of the keyword must be inserted in the order in which they occur into a 5x5 two dimensional array by rows, but if a letter is repeated in the keyword it is only used once in the two-dimensional array. Then the array is filled up with the remaining letters of the alphabet in order (excluding the 'Z').e.g. if the keyword was PHENOMENON the array would contain the following:

Next, the program will read in a series of lines containing either 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 the row and column will be noted: e.g. 'g' (when converted to upper case) occurs at row 2, column 1 in the above array. (Remember that indexes start at 0 in C++).

It will then be encrypted by reversing the row and column values, 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 they appear in the message.

A message that is already encrypted can be decrypted using exactly the same algorithm – the only difference is that the incoming message will be in upper case and the decrypted message will be in lower case.

You should process a file that contains the following:

HAPPINESS
D EVDEUOA XC GCERVLEWQ, FESS BC EUV OCWWAOX XLC HNUVRAV VCWWERS
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 MX IEY GA PEWSA
E the answer to the first question on the final may be true or it may be false
D OCUBREXNWEXMCUS YCN IEVA MX XHRCNBH XHMS IEOHMUA FRCGWAI
E advance to boardwalk, pass go and collect two hundred dollars
E make my day
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 --- popular mechanics 1948
E no computer will ever need more than 640k of memory -- bill gates in the mid eighties
D YCN EMUX UCXHMUB GNX E HCNUV VCB
D CUA VEY E OCIFNXAR LMWW LAMBH WASS XHEU E XCU --- FCFNWER IAOHEUMOS 1948
D UC OCIFNXAR LMWW ADAR UAAV ICRA XHEU 640Q CP IAICRY -- GMWW BEXAS MU XHA IMV AMB HXMAS
E the attack will start in $"population" minutes

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

The output should echo all the data, print out the two dimensional array as above, and print out the messages and their encoded equivalents (in either upper case (encrypting output) or lower case(decrypting output)).

So the first few lines of output on the above program would be something 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 one working before going on to the next. E.g. concentrate first on how to build the two-dimensional array from the keyword.
2.) Make sure you print out your 5x5 table using the key read from the 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 0
Add a comment Improve this question Transcribed image text
Request Professional Answer

Request Answer!

We need at least 8 more requests to produce the answer.

2 / 10 have requested this problem solution

The more requests, the faster the answer.

Request! (Login Required)


All students who have requested the answer will be notified once they are available.
Know the answer?
Add Answer to:
C++ Code
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two...

    ****************************************************************************************************************8 I want it same as the output and with details please and comments "For two thousand years, codemakers have fought to preserve secrets while codebreakers have tried their best to reveal them." - taken from Code Book, The Evolution of Secrecy from Mary, Queen of Scots to Quantum Cryptography by Simon Singh. The idea for this machine problem came from this book.You will encrypt and decrypt some messages using a simplified version of a code in the book. The...

  • Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could...

    Can i get Playfair Cipher for python 3 that encrypts a message and decrypts it, could you possibly make it as simple as you can without losing functionality. please include comments, that would help me better understand Example of PlayFair Cipher: https://en.wikipedia.org/wiki/Playfair_cipher The Playfair cipher uses a 5 by 5 table containing a key word or phrase. Memorization of the keyword and 4 simple rules was all that was required to create the 5 by 5 table and use the...

  • C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher....

    C PROGRAMMING Implement a function (using only #include library) that can encrypt/decrypt with a substitution cipher. cipher_sub (a, b, c, d) a is the string that has the data that will be encrypted or decrypted b is the string that has the result of the encrypt/decrypt c is the code string used for our substitution cipher (27 entries plus '\0' character) d is an integer that will pass two constants defined as ENC (encrypt) or DEC (decrypt) --> The function...

  • WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you...

    WE ARE USING PYTHON TO COMPLETE THIS ASSIGNMENT :) THANK YOU! In this programming assignment, you will write functions to encrypt and decrypt messages using simple substitution ciphers. Your solution MUST include: a function called encode that takes two parameters: key, a 26-character long string that identifies the ciphertext mapping for each letter of the alphabet, in order; plaintext, a string of unspecified length that represents the message to be encoded. encode will return a string representing the ciphertext. a...

  • Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt...

    Kindly follow the instructions provided carefully. C programming   Project 6, Program Design One way to encrypt a message is to use a date’s 6 digits to shift the letters. For example, if a date is picked as December 18, 1946, then the 6 digits are 121846. Assume the dates are in the 20th century. To encrypt a message, you will shift each letter of the message by the number of spaces indicated by the corresponding digit. For example, to encrypt...

  • Its a c++ program and please use basic code, I am a begineer. Please do show...

    Its a c++ program and please use basic code, I am a begineer. Please do show aall the steps Random monoalphabet cipher. The Caesar cipher, which shifts all letters by a fixed amount, is far too easy to crack. Here is a better idea. As the key, don't use numbers but words. Suppose the key word is FEATHER. Then first remove duplicate letters, yielding FEATHR, and append the other letters of the alphabet in reverse order: Now encrypt the letters...

  • C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string usi...

    C Programming - RSA encryption Hi there, I'm struggling with writing a C program to encrypt and decrypt a string using the RSA algorithm (C90 language only). It can contain ONLY the following libraries: stdio, stdlib, math and string. I want to use the following function prototypes to try and implement things: /*Check whether a given number is prime or not*/ int checkPrime(int n) /*to find gcd*/ int gcd(int a, int h) void Encrypt(); void Decrypt(); int getPublicKeys(); int getPrivateKeys();...

  • The following code is a C Program that is written for encrypting and decrypting a string....

    The following code is a C Program that is written for encrypting and decrypting a string. provide a full explanation of the working flow of the program. #include <stdio.h> int main() { int i, x; char str[100]; printf("\n Please enter a valid string: \t"); gets (str); printf ("\n Please choose one of the following options: \n"); printf ("1 = Encrypt the given string. \n"); printf("2 = Decrypt the entered string. \n"); scanf("%d",&x); // using switch case statements switch (x) {...

  • JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information...

    JAVA Problem: With the recent news about data breaches and different organizations having their clients’ information being exposed, it is becoming more and more important to find ways to protect our sensitive data. In this program we will develop a simple tool that helps users generate strong passwords, encrypt and decrypt data using some cyphering techniques. You will need to create two classes. The first class is your driver for the application and contains the main method. Name this class...

  • Cryptography, the study of secret writing, has been around for a very long time, from simplistic...

    Cryptography, the study of secret writing, has been around for a very long time, from simplistic techniques to sophisticated mathematical techniques. No matter what the form however, there are some underlying things that must be done – encrypt the message and decrypt the encoded message. One of the earliest and simplest methods ever used to encrypt and decrypt messages is called the Caesar cipher method, used by Julius Caesar during the Gallic war. According to this method, letters of the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT