What does the ShiftCharacter function do
char ShiftCharacter(char c){
bool upper = false;
if (isalpha(c)) {
if (isupper(c) ) {
upper = true;
c = static_cast(tolower(c));
}
c = static_cast (c+SHIFT);
if (c > 'z') {
c = static_cast (c-26);
}
if (upper) {
c = static_cast(toupper(c));
}
}
return c;
}
- Line 4 determines if the character is a alphabetic character, we do not encrypt non-alphabetic characters.
- Lines 5-8 determine if the character is upper case. We want to preserve upper case, but it is easier to encode if everything is the same case.
- Lines 10-13 shift the character by SHIFT letters in the alphabet. This is a circular shift, so z will wrap around to to c.
- Lines 15-17 restore the case of the original letter.