[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 "caesar.hpp"
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
Caesar::Caesar(int rotation) {
|
Caesar::Caesar(int rotation) {
|
||||||
setRotation(rotation);
|
setRotation(rotation);
|
||||||
|
@ -14,13 +15,17 @@ int Caesar::getRotation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
char Caesar::encryptChar(char toEncrypt) {
|
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) {
|
std::string Caesar::encryptString(std::string toEncrypt) {
|
||||||
|
|
1
main.cpp
1
main.cpp
|
@ -19,6 +19,7 @@ int main(int argc, char* argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Caesar caesar{rotation};
|
Caesar caesar{rotation};
|
||||||
|
std::cout << toEncrypt << std::endl;
|
||||||
std::cout << caesar.encryptString(toEncrypt) << std::endl;
|
std::cout << caesar.encryptString(toEncrypt) << std::endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue