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:
:mmZ\dxZmx]Zpgy
The message is obviously encrypted using the enemy's secret code. You have just learned that their encryption method is based on the ASCII code. Individual characters in a string are encoded using this system. (ex: the letter "A" is encoded using the number 65.)
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 uses key = 10 then the message "Hey" would be encrypted as
H = 72
e = 101
y = 121
Encrypted H = (72 + 10) = 82 = R in ASCII
..
..
you get "Hey" = "Ro$"
I have to write a program that decrypts the intercepted message. I know that they key used is a number between 1 and 100 and the program has to decode the message using all 100 keys.
I found out the correct key is 88 and it says "Attack At Dawn!" but I have to display all of them anyway. I've attached a printscreen of what the run program looks like.
this is what I have so far, and it may not make much sense because I am really confused:
#include <iostream>
#include <string>
using namespace std;
int main()
{
char EncryptedChar[] = ":mmZ\\dxZmx]Zpgy";
int key;
char OriginalChar;
if (OriginalChar + key > 126)
EncryptedChar = 32 + ((OriginalChar + key) - 127);
else
EncryptedChar = (OriginalChar + key);
for (key = 0; key <= 100, key++)
{
cout << "Key: " << key << " Decoded Message: " << EncryptedChar;
}
system("Pause");
return 0;
}