mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Updated to follow naming convetions from other ciphers
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
//Ciphers/Headers/Caesar.hpp
|
//Ciphers/Headers/Caesar.hpp
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 4-25-18
|
// Created: 4-25-18
|
||||||
//Modified: 4-25-18
|
//Modified: 5-5-18
|
||||||
//This file contains the declaration of the Caesar class
|
//This file contains the declaration of the Caesar class
|
||||||
//This class implements the Caesar Cipher and is inteded to be turned into a library
|
//This class implements the Caesar Cipher and is inteded to be turned into a library
|
||||||
|
|
||||||
@@ -13,17 +13,17 @@
|
|||||||
|
|
||||||
class Caesar{
|
class Caesar{
|
||||||
private:
|
private:
|
||||||
std::string input;
|
std::string inputString;
|
||||||
std::string output;
|
std::string outputString;
|
||||||
int shift;
|
int shift;
|
||||||
public:
|
public:
|
||||||
Caesar();
|
Caesar();
|
||||||
~Caesar();
|
~Caesar();
|
||||||
void setInput(std::string inputString);
|
void setInputString(std::string inputString);
|
||||||
std::string getInput() const;
|
std::string getInputString() const;
|
||||||
void setShift(int shiftAmount);
|
void setShift(int shiftAmount);
|
||||||
int getShift() const;
|
int getShift() const;
|
||||||
std::string getOutput() const;
|
std::string getOutputString() const;
|
||||||
std::string encode();
|
std::string encode();
|
||||||
std::string encode(int shiftAmount, std::string inputString);
|
std::string encode(int shiftAmount, std::string inputString);
|
||||||
std::string decode();
|
std::string decode();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//Ciphers/SourceFiles/Caesar.hpp
|
//Ciphers/SourceFiles/Caesar.hpp
|
||||||
//Matthew Ellison
|
//Matthew Ellison
|
||||||
// Created: 4-25-18
|
// Created: 4-25-18
|
||||||
//Modified: 4-25-18
|
//Modified: 5-5-18
|
||||||
//This file contains the implementation of the Caesar class
|
//This file contains the implementation of the Caesar class
|
||||||
//This class implements the Caesar Cipher and is inteded to be turned into a library
|
//This class implements the Caesar Cipher and is inteded to be turned into a library
|
||||||
|
|
||||||
@@ -11,23 +11,19 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
|
|
||||||
|
|
||||||
//std::string input;
|
|
||||||
//std::string output;
|
|
||||||
//int shift;
|
|
||||||
|
|
||||||
Caesar::Caesar(){
|
Caesar::Caesar(){
|
||||||
shift = 0;
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
Caesar::~Caesar(){
|
Caesar::~Caesar(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Caesar::setInput(std::string inputString){
|
void Caesar::setInputString(std::string input){
|
||||||
input = inputString;
|
inputString = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Caesar::getInput() const{
|
std::string Caesar::getInputString() const{
|
||||||
return input;
|
return inputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Caesar::setShift(int shiftAmount){
|
void Caesar::setShift(int shiftAmount){
|
||||||
@@ -39,15 +35,14 @@ int Caesar::getShift() const{
|
|||||||
return shift;
|
return shift;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Caesar::getOutput() const{
|
std::string Caesar::getOutputString() const{
|
||||||
return output;
|
return outputString;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Caesar::encode(){
|
std::string Caesar::encode(){
|
||||||
output = "";
|
|
||||||
char temp; //A temperary holder for the current working character
|
char temp; //A temperary holder for the current working character
|
||||||
for(int cnt = 0;cnt < input.size();++cnt){
|
for(int cnt = 0;cnt < inputString.size();++cnt){
|
||||||
temp = input.at(cnt);
|
temp = inputString.at(cnt);
|
||||||
//If it is a upper case letter shift it and wrap if necessary
|
//If it is a upper case letter shift it and wrap if necessary
|
||||||
if(isupper(temp)){
|
if(isupper(temp)){
|
||||||
temp += shift;
|
temp += shift;
|
||||||
@@ -72,22 +67,21 @@ std::string Caesar::encode(){
|
|||||||
}
|
}
|
||||||
//If it is whitespace, number, or punctuation just let it pass through
|
//If it is whitespace, number, or punctuation just let it pass through
|
||||||
//Add it to the output string
|
//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);
|
setShift(shiftAmount);
|
||||||
setInput(inputString);
|
setInputString(input);
|
||||||
return encode();
|
return encode();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Caesar::decode(){
|
std::string Caesar::decode(){
|
||||||
output = "";
|
|
||||||
char temp;
|
char temp;
|
||||||
for(int cnt = 0;cnt < input.size();++cnt){
|
for(int cnt = 0;cnt < inputString.size();++cnt){
|
||||||
temp = input.at(cnt);
|
temp = inputString.at(cnt);
|
||||||
//If it is an upper case letter shift it and wrap if necessary
|
//If it is an upper case letter shift it and wrap if necessary
|
||||||
if(isupper(temp)){
|
if(isupper(temp)){
|
||||||
temp -= shift;
|
temp -= shift;
|
||||||
@@ -110,18 +104,18 @@ std::string Caesar::decode(){
|
|||||||
}
|
}
|
||||||
//If it is whitespace, number, or punctuation just let it pass through
|
//If it is whitespace, number, or punctuation just let it pass through
|
||||||
//Add it to the output string
|
//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);
|
setShift(shiftAmount);
|
||||||
setInput(inputString);
|
setInputString(input);
|
||||||
return decode();
|
return decode();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Caesar::reset(){
|
void Caesar::reset(){
|
||||||
input = output = "";
|
inputString = outputString = "";
|
||||||
shift = 0;
|
shift = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user