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

This program decodes the secret message \":mmZ\\\\dxZmx]Zpgy\", by trying all 99

ID: 3630948 • Letter: T

Question

This program decodes the secret message ":mmZ\dxZmx]Zpgy", by trying all 99 possible keys in the decryption algorithm. You can define one of the following functions decrypt. This function decrypts the input C-string encoded using the key and puts it back into the C-string decoded

void decrypt(const char encoded[], char decoded[], int key);

or this function decrypts the input C-string message using the key and puts the result back to the C-string message itself.

void decrypt(char message[], int key);

We have already intercepted the enemy's encoding method as shown in the textbook and learned that the value of Key was below 100:

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

As opposed to encoding, we would like to use the decoding formula like this to get back the decrypted original characters:

If (EncryptedChar - Key < 32) then
OriginalChar = EncryptedChar - Key + 127 -32
else
OriginalChar = EncryptedChar - Key;

The C-string array must be large enough to hold the encoded or decoded characters. A program can be run like this:
=============================================================================
Key: 1 Decoded message: 9llY[cwYlwYofx
Key: 2 Decoded message: 8kkXZbvXkv[Xnew
... ... ...
Key: 99 Decoded message: 6iiVX`tVitYVlcu
Press any key to continue . . .
=============================================================================
Among all those lines, only one of the decoded messages makes sense while all others are as gibberish. You can recognize it at once. What's the message and its key? Tell your commander immediately without delay!

Explanation / Answer

please rate - thanks

#include<iostream>
using namespace std;
void decrypt(char message[], int key);
int main()
{char message[]={":mmZdxZmx]Zpgy"};
char encode[100];
int key = 1,i;
char choice;
for(key = 1; key <= 100; key++)
{for(i=0;message[i]!='';i++)
       encode[i]=message[i];
encode[i]='';
decrypt(encode,key);
cout<<"Key = "<<key<<endl;
cout<<encode<<endl;
cout<<"Does the decode make sense(y/n)?"<<endl;
cin>>choice;
choice = tolower(choice);
if(choice == 'y'||choice=='Y')
   exit(1);
}
return 0;
}

void decrypt(char message[], int key)
{int count;
for(count = 0; message[count]!=''; count++)
{if(message[count] +key >126)
    message[count] = 32+((message[count] + key) -127);
   else
    message[count] = message[count] + key;
}
}

#include<iostream>
using namespace std;
int main()
{char input[100];
char output[100];
int key,count;
cout<<"Enter encrypted code: ";
cin.getline(input,100);
for(key=1;key<=100;key++)
{for(count=0;input[count]!='';count++)
    {if(input[count]-key<32)
           output[count]=input[count]-key-32+127;
     else
           output[count]=input[count]-key;
     }
cout<<"Key "<<key<<": ";
cout<<output<<endl;
}
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