ASCII converter

I have to make a converter that will take the message :mmZ\dxZmx]Zpgy convert it to its corresponding ASCII number, use this formula

if(OriginalChar+Key > 126)
EncryptedChar = 32 + ((OrgiginalChar + Key) - 127);
else
EncryptedChar = (OrginalChar + Key);

The key in this problem is any number between 1 to 100 so I have to try the formula with every possible key till a message that makes sense is made.

So can anyone tell me what I'm doing wrong or point me in the right direction




#include <iostream>
#include <cstdlib>
using namespace std;

void converter(char OriginalChar, int Key);

int main()
{
char OriginalChar[16] = ":mmZ\\dxZmx]Zpgy";
int Key;

converter((int)OriginalChar, Key);

system("pause");
return 0;

}

void converter()(char OriginalChar, int Key)
{
char answer;

for (Key = 0; Key <= 100; Key++)
{
if (OriginalChar - Key < 32)
{
answer = (((OriginalChar - Key) + 127) - 32);
}
else
{
answer = (OriginalChar - Key);
}
cout << (char)answer;
}
}
Topic archived. No new replies allowed.