I was here earlier and got a hand adding to characters ASCII references to increment the cipher shift on each letter. However I have no idea how to fix the problem of characters being higher than ‘z’.
Can someone give me a hint towards how to wrap around when the characters reach the end of the alphabet. I don’t expect anyone to do my work for me, of course.
char decrypt(char letter)
{
int increment = 9;
if(letter == ' ')
{
return letter;
}
letter += increment;
return letter;
}
int main()
{
char message[446]; int i = 0; char space = ' ';
ifstream in("encryptedText.txt");
if(in.getline(message, 446))
{
while(message[i])
{
cout << decrypt(tolower(message[i])) << endl;
i++;
}
}
else
{cout << "Can't read file" << endl;}
cout << endl;
system("pause");
}
The modulo operation is your friend. Whenever integers form a ring instead of a sequence, a modulo operation can be applied, like:
You need to compute this in the integer space relative to
'a', of course, subtracting'a'appropriately.