mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-06 18:33:58 -05:00
Added functionality for Morse Code
This commit is contained in:
@@ -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 <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
|
||||
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";
|
||||
|
||||
Reference in New Issue
Block a user