Created class for Atbash cipher

This commit is contained in:
2018-04-30 12:19:01 -04:00
parent 96866aebd2
commit 59759f69bb
2 changed files with 105 additions and 0 deletions

74
SourceFiles/Atbash.cpp Normal file
View File

@@ -0,0 +1,74 @@
//Ciphers/SourceFiles/Atbash.cpp
//Matthew Ellison
// Created: 4-30-18
//Modified: 4-30-18
//This file contains the implementation of the Atbash class
#include "../Headers/Atbash.hpp"
#include <cctype>
Atbash::Atbash(){
}
Atbash::~Atbash(){
}
void Atbash::setInputString(std::string input){
//Make sure inputString is empty
reset();
//Strip all punctuation and whitespace from input and make all letters capital
for(int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt];
//If it is upper case add it to the inputString
if(isupper(letter)){
inputString += letter;
}
//If it is lower case make it upper case and add it to the inputString
else if(islower(letter)){
inputString += toupper(letter);
}
//If it is anything else ignore it
}
}
std::string Atbash::getInputString() const{
return inputString;
}
std::string Atbash::getOutputString() const{
return outputString;
}
std::string Atbash::encode(){
//Step through every element in the inputString and shift it the correct amount
for(int cnt = 0;cnt < inputString.size();++cnt){
outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A')));
}
return outputString;
}
std::string Atbash::encode(std::string input){
setInputString(input);
return encode();
}
std::string Atbash::decode(){
//Make sure outputString is empty
outputString = "";
for(int cnt = 0;cnt < inputString.size();++cnt){
outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A')));
}
return outputString;
}
std::string Atbash::decode(std::string input){
setInputString(input);
return decode();
}
void Atbash::reset(){
inputString = outputString = "";
}