Caesar/caesar.cpp

40 lines
720 B
C++

#include "caesar.hpp"
#include <string>
#include <iostream>
Caesar::Caesar(int rotation) {
setRotation(rotation);
}
void Caesar::setRotation(int rotation) {
this->rotation = rotation;
}
int Caesar::getRotation() {
return rotation;
}
char Caesar::encryptChar(char toEncrypt) {
int newChar = toEncrypt + rotation;
bool substractTwo = false;
while(newChar > MAX) newChar -= MAX;
substractTwo = newChar < MIN;
while(newChar < MIN) newChar += MIN;
if(substractTwo) newChar -= 2;
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;
}