mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added new documentation
This commit is contained in:
@@ -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]){
|
||||
|
||||
2
main.cpp
2
main.cpp
@@ -1,7 +1,7 @@
|
||||
//Ciphers/main.cpp
|
||||
//Matthew Ellison
|
||||
// Created: 4-25-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
|
||||
|
||||
|
||||
59
testMain.hpp
59
testMain.hpp
@@ -1,7 +1,7 @@
|
||||
//Ciphers/testMain.hpp
|
||||
//Matthew Ellison
|
||||
// Created: 4-30-18
|
||||
//Modified: 4-30-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
|
||||
|
||||
@@ -25,37 +25,92 @@
|
||||
#define ATBASH_TEST
|
||||
#define MORSE_TEST
|
||||
#define AUTOKEY_TEST
|
||||
/**
|
||||
* @brief Helper for determining the state of a cipher when an error occured
|
||||
*
|
||||
*/
|
||||
enum codingState { ENCODE, DECODE };
|
||||
/**
|
||||
* @brief Creates an error message
|
||||
*
|
||||
* @param type Determines whether the cipher was encoding or decoding when an error occured
|
||||
* @param input The string that was input into the cipher
|
||||
* @param output The string that was the expected output of the cipher
|
||||
* @param cipher The string that was the actual output of the cipher
|
||||
* @return The appropriate error message
|
||||
*/
|
||||
std::string testingError(codingState type, const std::string& input, const std::string& output, const std::string& cipher);
|
||||
#endif //TEST_VERSION definition
|
||||
|
||||
#ifdef CAESAR_TEST
|
||||
/**
|
||||
* @brief Runs several tests on the Caesar cipher, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool caesarTest(std::string& errorString);
|
||||
#endif //CAESAR_TEST
|
||||
|
||||
#ifdef PLAYFAIR_TEST
|
||||
/**
|
||||
* @brief Runs several tests on the Playfair cipher, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool playfairTest(std::string& errorString);
|
||||
#endif //PLAYFAIR_TEST
|
||||
|
||||
#ifdef VIGENERE_TEST
|
||||
/**
|
||||
* @brief Runs several tests on the Vigenere cipher, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool vigenereTest(std::string& errorString);
|
||||
#endif //VIGENERE_TEST
|
||||
|
||||
#ifdef ATBASH_TEST
|
||||
/**
|
||||
* @brief Runs several tests on the Atbash cipher, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool atbashTest(std::string& errorString);
|
||||
#endif //ATBASH_TEST
|
||||
|
||||
#ifdef MORSE_TEST
|
||||
/**
|
||||
* @brief Runs several tests on Morse code, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool morseTest(std::string& errorString);
|
||||
#endif //MORSE_TEST
|
||||
|
||||
#ifdef AUTOKEY_TEST
|
||||
/**
|
||||
* @brief Runs several tests on the Autokey cipher, checking if encoding and decoding are working propperly
|
||||
*
|
||||
* @param errorString A string to store any error messages
|
||||
* @return true If all tests completed successfully
|
||||
* @return false If 1 or more tests failed
|
||||
*/
|
||||
bool autokeyTest(std::string& errorString);
|
||||
#endif //AUTOKEY_TEST
|
||||
|
||||
|
||||
#ifdef TEST_VERSION
|
||||
|
||||
//A different main function that facilitates all tests
|
||||
int main(int argc, char** argv){
|
||||
bool testResult = false;
|
||||
std::string resultString = "";
|
||||
|
||||
Reference in New Issue
Block a user