[Bug fix]
This commit is contained in:
parent
597d48ba0f
commit
1da6fa613c
13
caesar.cpp
13
caesar.cpp
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue