//Ciphers/main.cpp //Matthew Ellison // Created: 4-25-18 //Modified: 12-10-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 /* Copyright (C) 2018 Matthew Ellison This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ //The header files #include "Headers/Caesar.hpp" #include "Headers/Playfair.hpp" #include "Headers/Vigenere.hpp" #include "Headers/Atbash.hpp" #include "Headers/Morse.hpp" #include #include //If this is the test version include the appropriate functions from the file #ifdef TEST_VERSION #include "testHandler.hpp" //This inserts the main function with all of the test functions #else //We need these files for normal opperations #include "helperFunctions.hpp" #include #endif //TEST_VERSION int main(int argc, char** argv){ //If this is the test version of the program run the test function #ifdef TEST_VERSION testHandler(argc, argv); //Otherwise handle the program normally #else //TEST_VERSION bool cipherFlags[SIZE]; std::string inputFileName, outputFileName, cipherString; std::ifstream inputFile; std::ofstream outputFile; //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(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(); #endif //TEST_VERSION return 0; }