//Ciphers/main.cpp //Matthew Ellison // Created: 4-25-18 //Modified: 4-30-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 ///The header files #include "Headers/Caesar.hpp" #include "Headers/Playfair.hpp" #include "Headers/Vigenere.hpp" #include "Headers/Atbash.hpp" #include #include ///Test definitions //#define TEST_VERSION //Main functions #ifdef TEST_VERSION #include "testMain.hpp" //This inserts the main function with all of the test functions #else //TEST_VERSION main function #include "helperFunctions.hpp" #include int main(int argc, char** argv){ bool cipherFlags[SIZE]; std::string inputFileName, outputFileName, cipherString; std::ifstream inputFile; std::ofstream outputFile; setFlagStrings(); //Make sure the flags are all false by default for(int cnt = 0;cnt < SIZE;++cnt){ cipherFlags[cnt] = false; } //Check what flags were set getFlags(argc, argv, cipherFlags, inputFileName, outputFileName); //Make sure that only one of the ciphers was selected if(!checkFlags(cipherFlags)){ std::cout << "The flags given were invalid" << std::endl; return 0; } //Check if output file can be opened if(cipherFlags[OUTPUT_FILE]){ outputFile.open(outputFileName); if(outputFile.fail()){ std::cout << "The output file could not be opened" << std::endl; return 0; } } //Check if input file can be opened if(cipherFlags[INPUT_FILE]){ inputFile.open(inputFileName); if(inputFile.fail()){ std::cout << "The input file could not be opened" << std::endl; return 0; } } //Run the appropriate functions for the cipher Fn cipherFunction = getCipher(cipherFlags); cipherString = cipherFunction(inputFile, cipherFlags[ENCODE]); /* if(cipherFlags[CAESAR]){ cipherString = runCaesar(inputFile, cipherFlags[ENCODE]); } else if(cipherFlags[PLAYFAIR]){ cipherString = runPlayfair(inputFile, cipherFlags[ENCODE]); } else if(cipherFlags[VIGENERE]){ cipherString = runVigenere(inputFile, cipherFlags[ENCODE]); } else{ cipherString = "There is a big problem. No valid cipher option was given.\n"; return 0; } */ if(failFlag){ std::cout << cipherString << std::endl; return 0; } //Decide where the cipher will be output if(cipherFlags[OUTPUT_FILE]){ outputFile << cipherString << std::endl; } else{ std::cout << cipherString << std::endl; } inputFile.close(); outputFile.close(); return 0; } #endif //TEST_VERSION