[Bug fix 2]
This commit is contained in:
parent
1da6fa613c
commit
8655f81026
13
caesar.cpp
13
caesar.cpp
|
@ -7,7 +7,7 @@ Caesar::Caesar(int rotation) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Caesar::setRotation(int rotation) {
|
void Caesar::setRotation(int rotation) {
|
||||||
this->rotation = rotation;
|
this->rotation = rotation - MAX * (int)(rotation / MAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
int Caesar::getRotation() {
|
int Caesar::getRotation() {
|
||||||
|
@ -16,14 +16,13 @@ int Caesar::getRotation() {
|
||||||
|
|
||||||
char Caesar::encryptChar(char toEncrypt) {
|
char Caesar::encryptChar(char toEncrypt) {
|
||||||
int newChar = toEncrypt + rotation;
|
int newChar = toEncrypt + rotation;
|
||||||
bool substractTwo = false;
|
|
||||||
|
|
||||||
while(newChar > MAX) newChar -= MAX;
|
bool substractTwo = newChar > MAX;
|
||||||
|
|
||||||
substractTwo = newChar < MIN;
|
while(newChar > MAX) {
|
||||||
while(newChar < MIN) newChar += MIN;
|
newChar -= MAX;
|
||||||
|
newChar += MIN - 1;
|
||||||
if(substractTwo) newChar -= 2;
|
}
|
||||||
|
|
||||||
return (char)newChar;
|
return (char)newChar;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Caesar {
|
||||||
std::string encryptString(std::string toEncrypt);
|
std::string encryptString(std::string toEncrypt);
|
||||||
private:
|
private:
|
||||||
int rotation;
|
int rotation;
|
||||||
const int MIN = 33;
|
const int MIN = 32;
|
||||||
const int MAX = 126;
|
const int MAX = 126;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue