Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Your country is at war and your enemies are using a secret code to communicate w

ID: 3633645 • Letter: Y

Question

Your country is at war and your enemies are using a secret code to communicate with each other. You have managed to intercept a message that reads as follows:

:mmZdxZmx]Zpgy

The message is obviously encrypted using the enemy's secret code. You have just learned that their encryption method is based upon the ASCII code. Appendix 3 of your book shows the ACII character set. Individual characters in a string are encoded using this system. For example, the letter "A" is encoded using the number 65 and "B" is encoded using the number 66.

Your enemy's secret code takes each letter of the message and encrypts it as follows:

If(OriginalChar + Key > 126) then EncryptedChar = 32 + ((OriginalChar + Key ) - 127)

else EncryptedChar = (OriginalChar + Key)

For example, if the enemy used Key = 10 then the message "Hey" would be encrypted as:

Character

ASCII Code

H

72

e

101

y

121

Encrypted H = (72 + 10) = 82 = R in ASCII

Encrypted e = (101 + 10) = 111 = o in ASCII

Encrypted y = (121 + 10) - 127 = 36 = $ in ASCII

Consequently, "Hey" would be transmitted as "Ro$".

Write a program that decrypts the intercepted message. You only know that the key used is a number between 1 and 100. Your program should try to decode the message using all possible keys between 1 and 100. When you try the valid key, the message will make sense. For all other keys the message will appear as gibberish.

Use C++-Strings for this assignment. NOT C Strings.

Character

ASCII Code

H

72

e

101

y

121

Explanation / Answer

please rate - thanks


#include<iostream>
using namespace std;
int main()
{char encode[]={":mmZdxZmx]Zpgy"};
char decode[100];
int key = 1,count;
char choice;
for(key = 1; key <= 100; key++)
{for(count = 0; count < strlen(encode); count++)
{if(encode[count] +key >126)
    decode[count] = 32+((encode[count] + key) -127);
   else
    decode[count] = encode[count] + key;
}
cout<<"Key = "<<key<<endl;
cout<<decode<<endl;
cout<<"Does the decode make sense(y/n)?"<<endl;
cin>>choice;
choice = tolower(choice);
if(choice == 'y'||choice=='Y')
   exit(1);
}
system("pause");
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote