Updated to follow naming convetions from other ciphers

This commit is contained in:
2018-05-05 15:43:42 -04:00
parent e03b6ae6fe
commit bd9e66f176
2 changed files with 27 additions and 33 deletions

View File

@@ -1,7 +1,7 @@
//Ciphers/Headers/Caesar.hpp
//Matthew Ellison
// Created: 4-25-18
//Modified: 4-25-18
//Modified: 5-5-18
//This file contains the declaration of the Caesar class
//This class implements the Caesar Cipher and is inteded to be turned into a library
@@ -13,17 +13,17 @@
class Caesar{
private:
std::string input;
std::string output;
std::string inputString;
std::string outputString;
int shift;
public:
Caesar();
~Caesar();
void setInput(std::string inputString);
std::string getInput() const;
void setInputString(std::string inputString);
std::string getInputString() const;
void setShift(int shiftAmount);
int getShift() const;
std::string getOutput() const;
std::string getOutputString() const;
std::string encode();
std::string encode(int shiftAmount, std::string inputString);
std::string decode();

View File

@@ -1,7 +1,7 @@
//Ciphers/SourceFiles/Caesar.hpp
//Matthew Ellison
// Created: 4-25-18
//Modified: 4-25-18
//Modified: 5-5-18
//This file contains the implementation of the Caesar class
//This class implements the Caesar Cipher and is inteded to be turned into a library
@@ -11,23 +11,19 @@
#include <cctype>
//std::string input;
//std::string output;
//int shift;
Caesar::Caesar(){
shift = 0;
reset();
}
Caesar::~Caesar(){
}
void Caesar::setInput(std::string inputString){
input = inputString;
void Caesar::setInputString(std::string input){
inputString = input;
}
std::string Caesar::getInput() const{
return input;
std::string Caesar::getInputString() const{
return inputString;
}
void Caesar::setShift(int shiftAmount){
@@ -39,15 +35,14 @@ int Caesar::getShift() const{
return shift;
}
std::string Caesar::getOutput() const{
return output;
std::string Caesar::getOutputString() const{
return outputString;
}
std::string Caesar::encode(){
output = "";
char temp; //A temperary holder for the current working character
for(int cnt = 0;cnt < input.size();++cnt){
temp = input.at(cnt);
for(int cnt = 0;cnt < inputString.size();++cnt){
temp = inputString.at(cnt);
//If it is a upper case letter shift it and wrap if necessary
if(isupper(temp)){
temp += shift;
@@ -72,22 +67,21 @@ std::string Caesar::encode(){
}
//If it is whitespace, number, or punctuation just let it pass through
//Add it to the output string
output += temp;
outputString += temp;
}
return output;
return outputString;
}
std::string Caesar::encode(int shiftAmount, std::string inputString){
std::string Caesar::encode(int shiftAmount, std::string input){
setShift(shiftAmount);
setInput(inputString);
setInputString(input);
return encode();
}
std::string Caesar::decode(){
output = "";
char temp;
for(int cnt = 0;cnt < input.size();++cnt){
temp = input.at(cnt);
for(int cnt = 0;cnt < inputString.size();++cnt){
temp = inputString.at(cnt);
//If it is an upper case letter shift it and wrap if necessary
if(isupper(temp)){
temp -= shift;
@@ -110,18 +104,18 @@ std::string Caesar::decode(){
}
//If it is whitespace, number, or punctuation just let it pass through
//Add it to the output string
output += temp;
outputString += temp;
}
return output;
return outputString;
}
std::string Caesar::decode(int shiftAmount, std::string inputString){
std::string Caesar::decode(int shiftAmount, std::string input){
setShift(shiftAmount);
setInput(inputString);
setInputString(input);
return decode();
}
void Caesar::reset(){
input = output = "";
inputString = outputString = "";
shift = 0;
}