So I'm writing a program to process simple ROT13 encryption (where you read in a string and move each letter 13 places across in the alphabet to hide it, then if you do it again, it reverts back to it's original text). eg. 'HELLO' would encrypt to 'URYYB'
My code works for all values, uppercase and lowercase, except for lowercase 's' through to 'z' (ascii values 115 to 122)
I ran it through a debugger and saw that when the line (i commented at the line im talking about) in the code which should only +13 to its value, turns 115 into -128, instead of 128. This gives me a weird value and i can't figure out why.
Code:
void encrypt(char *input, int upperindex, int lowerindex)
{
int i;
for(i = 0; i < SIZE; i++)
{
/** THIS IS FOR LOWERCASE CHARACTERS**/
if((input[i]<123) &&(input[i]>96))
{
input[i] = input[i] + 13; /** THIS IS THE LINE THAT GOES WRONG**/
if(input [i] > 122)
{
input[i] = lowerindex + ( (input[i]) % 122 );
}
}
/** THIS IS FOR UPPERCASE CHARACTERS**/
if((input[i]<91)&&(input[i]>64))
{
input[i] = input[i] + 13;
if(input[i] > 90)
{
input[i] = upperindex + ( (input[i]) % 90);
}
}
}
}
can someone help me out as to what could be making this code go wrong for only select values?
Bookmarks