diff --git a/helperFunctions.hpp b/helperFunctions.hpp index 4dbf5d9..36efbc6 100644 --- a/helperFunctions.hpp +++ b/helperFunctions.hpp @@ -14,12 +14,14 @@ #include "Headers/Caesar.hpp" #include "Headers/Playfair.hpp" #include "Headers/Vigenere.hpp" +#include "Headers/Atbash.hpp" +#include "Headers/Morse.hpp" #include #include #include -enum CipherFlagLocation { CAESAR, PLAYFAIR, VIGENERE, ATBASH, NUM_CIPHERS, +enum CipherFlagLocation { CAESAR, PLAYFAIR, VIGENERE, ATBASH, MORSE, NUM_CIPHERS, ENCODE, DECODE, INPUT_FILE, OUTPUT_FILE, SIZE }; std::string flagStrings[SIZE]; //Error handling @@ -96,6 +98,7 @@ void setFlagStrings(){ flagStrings[PLAYFAIR] = "-p"; flagStrings[VIGENERE] = "-v"; flagStrings[ATBASH] = "-a"; + flagStrings[MORSE] = "-m"; flagStrings[ENCODE] = "-e"; flagStrings[DECODE] = "-d"; flagStrings[INPUT_FILE] = "-i"; @@ -225,6 +228,34 @@ std::string runAtbash(std::ifstream& infile, bool encode){ return cipherString; } +std::string runMorse(std::ifstream& infile, bool encode){ + std::string inputString, cipherString; + Morse cipher; + //Check if the input file is open + if(infile.is_open()){ + std::getline(infile, inputString); + if(infile.fail()){ + failFlag = true; + cipherString = "Input file has an incorrect format\n"; + } + } + //Otherwise prompt for the appropriate strings + else{ + std::cout << "Enter the input string: "; + std::getline(std::cin, inputString); + } + + //Run the correct cipher + if(encode){ + cipherString = cipher.encode(inputString); + } + else{ + cipherString = cipher.decode(inputString); + } + + return cipherString; +} + //Returns the correct function for the flags that are set Fn getCipher(const bool cipherFlags[]){ if(cipherFlags[CAESAR]){ @@ -239,6 +270,9 @@ Fn getCipher(const bool cipherFlags[]){ else if(cipherFlags[ATBASH]){ return runAtbash; } + else if(cipherFlags[MORSE]){ + return runMorse; + } //If it didn't trip one of the flags, there was an error before this else{ std::cout << "There was an error selecting the appropriate function"; diff --git a/main.cpp b/main.cpp index 31cfae1..859fb6c 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ #include "Headers/Playfair.hpp" #include "Headers/Vigenere.hpp" #include "Headers/Atbash.hpp" +#include "Headers/Morse.hpp" #include #include