From 8655f81026f7261bc006aaf261ea48cbca387258 Mon Sep 17 00:00:00 2001 From: xoy Date: Fri, 14 Jun 2024 00:20:44 +0200 Subject: [PATCH] [Bug fix 2] --- caesar.cpp | 13 ++++++------- caesar.hpp | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/caesar.cpp b/caesar.cpp index 0ee4afd..0e7e3e8 100644 --- a/caesar.cpp +++ b/caesar.cpp @@ -7,7 +7,7 @@ Caesar::Caesar(int rotation) { } void Caesar::setRotation(int rotation) { - this->rotation = rotation; + this->rotation = rotation - MAX * (int)(rotation / MAX); } int Caesar::getRotation() { @@ -16,14 +16,13 @@ int Caesar::getRotation() { char Caesar::encryptChar(char toEncrypt) { int newChar = toEncrypt + rotation; - bool substractTwo = false; - while(newChar > MAX) newChar -= MAX; + bool substractTwo = newChar > MAX; - substractTwo = newChar < MIN; - while(newChar < MIN) newChar += MIN; - - if(substractTwo) newChar -= 2; + while(newChar > MAX) { + newChar -= MAX; + newChar += MIN - 1; + } return (char)newChar; } diff --git a/caesar.hpp b/caesar.hpp index 16756d8..490df32 100644 --- a/caesar.hpp +++ b/caesar.hpp @@ -12,7 +12,7 @@ class Caesar { std::string encryptString(std::string toEncrypt); private: int rotation; - const int MIN = 33; + const int MIN = 32; const int MAX = 126; };