Added new documentation

This commit is contained in:
2018-05-05 15:13:19 -04:00
parent e061b70cd7
commit 539e6c33ec

View File

@@ -1,22 +1,33 @@
//Ciphers/SourceFiles/Atbash.cpp //Ciphers/SourceFiles/Atbash.cpp
//Matthew Ellison //Matthew Ellison
// Created: 4-30-18 // Created: 4-30-18
//Modified: 4-30-18 //Modified: 5-5-18
//This file contains the implementation of the Atbash class //This file contains the implementation of the Atbash class
#include "../Headers/Atbash.hpp" #include "../Headers/Atbash.hpp"
#include <cctype> #include <cctype>
/**
* @brief Construct a new Atbash object
*
*/
Atbash::Atbash(){ Atbash::Atbash(){
} }
/**
* @brief Destroy the Atbash object
*
*/
Atbash::~Atbash(){ Atbash::~Atbash(){
} }
/**
* @brief Strips all invalid characters from input and sets it to inputString
*
* @param input The string that you wish to encode or decode
*/
void Atbash::setInputString(std::string input){ void Atbash::setInputString(std::string input){
//Make sure inputString is empty
reset();
//Strip all punctuation and whitespace from input and make all letters capital //Strip all punctuation and whitespace from input and make all letters capital
for(int cnt = 0;cnt < input.size();++cnt){ for(int cnt = 0;cnt < input.size();++cnt){
char letter = input[cnt]; char letter = input[cnt];
@@ -32,14 +43,29 @@ void Atbash::setInputString(std::string input){
} }
} }
/**
* @brief Returns the stripped inputString
*
* @return The current inputString
*/
std::string Atbash::getInputString() const{ std::string Atbash::getInputString() const{
return inputString; return inputString;
} }
/**
* @brief Returns the current outputString
*
* @return The current outputString
*/
std::string Atbash::getOutputString() const{ std::string Atbash::getOutputString() const{
return outputString; return outputString;
} }
/**
* @brief Uses the Atbash cipher to encode inputString and store it in outputString
*
* @return The encoded inputString (outputString)
*/
std::string Atbash::encode(){ std::string Atbash::encode(){
//Step through every element in the inputString and shift it the correct amount //Step through every element in the inputString and shift it the correct amount
for(int cnt = 0;cnt < inputString.size();++cnt){ for(int cnt = 0;cnt < inputString.size();++cnt){
@@ -49,14 +75,25 @@ std::string Atbash::encode(){
return outputString; return outputString;
} }
/**
* @brief A simple interface that makes sure inputString is set and encodes it using the Atbash cipher
*
* @param input The string that you wish to encode
* @return The encoded string
*/
std::string Atbash::encode(std::string input){ std::string Atbash::encode(std::string input){
//Make sure everything is empty before you begin
reset();
setInputString(input); setInputString(input);
return encode(); return encode();
} }
/**
* @brief Uses the Atbash cipher to decode inputString and store it in outputString
*
* @return The decoded inputString (outputString)
*/
std::string Atbash::decode(){ std::string Atbash::decode(){
//Make sure outputString is empty
outputString = "";
for(int cnt = 0;cnt < inputString.size();++cnt){ for(int cnt = 0;cnt < inputString.size();++cnt){
outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A'))); outputString += (inputString[cnt] + 25 - (2 * (inputString[cnt] - 'A')));
} }
@@ -64,11 +101,23 @@ std::string Atbash::decode(){
return outputString; return outputString;
} }
/**
* @brief A simple interface that makes sure inputString is set and decodes it using the Atbash cipher
*
* @param input The string that you wish to encode
* @return The decoded string
*/
std::string Atbash::decode(std::string input){ std::string Atbash::decode(std::string input){
//Make sure everything is empty before you begin
reset();
setInputString(input); setInputString(input);
return decode(); return decode();
} }
/**
* @brief Resets all variables
*
*/
void Atbash::reset(){ void Atbash::reset(){
inputString = outputString = ""; inputString = outputString = "";
} }