Added exceptions for whitespace

This commit is contained in:
datalore 2023-10-25 12:29:28 +02:00
parent 75546a8619
commit 013c05f2dd
3 changed files with 15 additions and 0 deletions

View File

@ -5,6 +5,11 @@ void shift(char* text, int key)
std::cout << key << ": "; std::cout << key << ": ";
for(int i = 0; text[i] != 0; ++i) for(int i = 0; text[i] != 0; ++i)
{ {
if(text[i] == ' ')
{
std::cout << ' ';
continue;
}
char c = std::tolower(text[i])-key; char c = std::tolower(text[i])-key;
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;

View File

@ -15,6 +15,11 @@ int main(int argc, char** argv)
for(int i = 0; text[i] != 0; ++i) for(int i = 0; text[i] != 0; ++i)
{ {
if(text[i] == ' ')
{
std::cout << ' ';
continue;
}
char c = std::tolower(text[i])+key; char c = std::tolower(text[i])+key;
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;

View File

@ -20,6 +20,11 @@ int main(int argc, char** argv)
int ki = 0; int ki = 0;
for(int pi = 0; text[pi] != 0; ++pi) for(int pi = 0; text[pi] != 0; ++pi)
{ {
if(text[i] == ' ')
{
std::cout << ' ';
continue;
}
char c = std::tolower(text[pi]) + keyvalue(key[ki]); char c = std::tolower(text[pi]) + keyvalue(key[ki]);
if(c < 'a') c+=26; if(c < 'a') c+=26;
if(c > 'z') c-=26; if(c > 'z') c-=26;