diff --git a/caesar.cpp b/caesar.cpp index c9bb5de..0ee4afd 100644 --- a/caesar.cpp +++ b/caesar.cpp @@ -1,5 +1,6 @@ #include "caesar.hpp" #include +#include Caesar::Caesar(int rotation) { setRotation(rotation); @@ -14,13 +15,17 @@ int Caesar::getRotation() { } char Caesar::encryptChar(char toEncrypt) { - char newChar = toEncrypt + rotation; + int newChar = toEncrypt + rotation; + bool substractTwo = false; - if(newChar > MAX) newChar -= MAX; + while(newChar > MAX) newChar -= MAX; - if(newChar < MIN) newChar += MIN; + substractTwo = newChar < MIN; + while(newChar < MIN) newChar += MIN; - return newChar; + if(substractTwo) newChar -= 2; + + return (char)newChar; } std::string Caesar::encryptString(std::string toEncrypt) { diff --git a/main.cpp b/main.cpp index 993a6af..05f3b72 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ int main(int argc, char* argv[]) { } Caesar caesar{rotation}; + std::cout << toEncrypt << std::endl; std::cout << caesar.encryptString(toEncrypt) << std::endl; return 0;