Added new documentation

This commit is contained in:
2018-05-08 11:53:16 -04:00
parent 1cf1898664
commit 0e4a954cc4
3 changed files with 127 additions and 5 deletions

View File

@@ -1,12 +1,11 @@
//Ciphers/helperFunctions.hpp
//Matthew Ellison
// Created: 4-29-18
//Modified: 5-2-18
//Modified: 5-8-18
//This file contains the driver function and the test functions for the Cipher program
//This program will use some simple ciphers that are no longer widely used but still fun to play with
#ifndef HELPER_FUNCTIONS_HPP
#define HELPER_FUNCTIONS_HPP
@@ -33,6 +32,15 @@ typedef std::string (*Fn)(std::ifstream&, bool);
/**
* @brief Takes all of the arguments that were given to the program and sets boolean flags inside the program that will change behavior
*
* @param argc The number of arguments given
* @param argv The arguments given
* @param cipherFlags The array of booleans that represent the possible options passed in
* @param inputFileString The name of the input file, if given
* @param outputFileString The name of the output file if given
*/
void getFlags(int argc, char** argv, bool cipherFlags[], std::string& inputFileString, std::string& outputFileString){
//Cycle through every argument
bool valid = false;
@@ -67,6 +75,13 @@ void getFlags(int argc, char** argv, bool cipherFlags[], std::string& inputFileS
}
}
/**
* @brief Checks that the flags given are valid
*
* @param flags All of the flags that the program can have
* @return true If valid options were chosen
* @return false If invalid options were chosen
*/
bool checkFlags(bool flags[]){
int counter = 0;
bool correct = false;
@@ -90,6 +105,10 @@ bool checkFlags(bool flags[]){
return correct;
}
/**
* @brief Set the array of strings that controls what each flag should look
*
*/
void setFlagStrings(){
flagStrings[CAESAR] = "-c";
flagStrings[PLAYFAIR] = "-p";
@@ -103,6 +122,13 @@ void setFlagStrings(){
flagStrings[OUTPUT_FILE] = "-o";
}
/**
* @brief Run the appropriate commands to use a Caesar cipher
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runCaesar(std::ifstream& infile, bool encode){
std::string inputString, cipherString;
int offset;
@@ -140,6 +166,13 @@ std::string runCaesar(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Run the appropriate commands to use a Playfair cipher
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runPlayfair(std::ifstream& infile, bool encode){
std::string keyword, inputString, cipherString;
Playfair cipher;
@@ -175,6 +208,13 @@ std::string runPlayfair(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Run the appropriate commands to use a Vigenere cipher
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runVigenere(std::ifstream& infile, bool encode){
std::string keyword, inputString, cipherString;
Vigenere cipher;
@@ -210,6 +250,13 @@ std::string runVigenere(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Run the appropriate commands to use an Atbash cipher
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runAtbash(std::ifstream& infile, bool encode){
std::string inputString, cipherString;
Atbash cipher;
@@ -242,6 +289,13 @@ std::string runAtbash(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Run the appropriate commands to use Morse code
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runMorse(std::ifstream& infile, bool encode){
std::string inputString, cipherString;
Morse cipher;
@@ -274,6 +328,13 @@ std::string runMorse(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Run the appropriate commands to use an Autokey cipher
*
* @param infile The input file if one was provided
* @param encode Whether the encoding flag was set. True if encoding, false if decoding
* @return The new message
*/
std::string runAutokey(std::ifstream& infile, bool encode){
std::string keyword, inputString, cipherString;
Autokey cipher;
@@ -309,6 +370,12 @@ std::string runAutokey(std::ifstream& infile, bool encode){
return cipherString;
}
/**
* @brief Uses the flags to determine which cipher needs to be run
*
* @param cipherFlags The possible flags given to the program
* @return The appropriate run___ function based on the flags
*/
//Returns the correct function for the flags that are set
Fn getCipher(const bool cipherFlags[]){
if(cipherFlags[CAESAR]){