[Bug fix]

This commit is contained in:
xoy 2024-06-13 18:37:44 +02:00
parent 597d48ba0f
commit 1da6fa613c
2 changed files with 10 additions and 4 deletions

View File

@ -1,5 +1,6 @@
#include "caesar.hpp"
#include <string>
#include <iostream>
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) {

View File

@ -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;