Caesar/caesar.cpp

39 lines
685 B
C++

#include "caesar.hpp"
#include <string>
#include <iostream>
Caesar::Caesar(int rotation) {
setRotation(rotation);
}
void Caesar::setRotation(int rotation) {
this->rotation = rotation - MAX * (int)(rotation / MAX);
}
int Caesar::getRotation() {
return rotation;
}
char Caesar::encryptChar(char toEncrypt) {
int newChar = toEncrypt + rotation;
bool substractTwo = newChar > MAX;
while(newChar > MAX) {
newChar -= MAX;
newChar += MIN - 1;
}
return (char)newChar;
}
std::string Caesar::encryptString(std::string toEncrypt) {
std::string encrypted = "";
for(int i = 0; i < toEncrypt.length(); i++) {
encrypted += encryptChar(toEncrypt[i]);
}
return encrypted;
}