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/Caesar.hpp"
|
||||||
#include "Headers/Playfair.hpp"
|
#include "Headers/Playfair.hpp"
|
||||||
#include "Headers/Vigenere.hpp"
|
#include "Headers/Vigenere.hpp"
|
||||||
|
#include "Headers/Atbash.hpp"
|
||||||
|
#include "Headers/Morse.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#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 };
|
ENCODE, DECODE, INPUT_FILE, OUTPUT_FILE, SIZE };
|
||||||
std::string flagStrings[SIZE];
|
std::string flagStrings[SIZE];
|
||||||
//Error handling
|
//Error handling
|
||||||
@@ -96,6 +98,7 @@ void setFlagStrings(){
|
|||||||
flagStrings[PLAYFAIR] = "-p";
|
flagStrings[PLAYFAIR] = "-p";
|
||||||
flagStrings[VIGENERE] = "-v";
|
flagStrings[VIGENERE] = "-v";
|
||||||
flagStrings[ATBASH] = "-a";
|
flagStrings[ATBASH] = "-a";
|
||||||
|
flagStrings[MORSE] = "-m";
|
||||||
flagStrings[ENCODE] = "-e";
|
flagStrings[ENCODE] = "-e";
|
||||||
flagStrings[DECODE] = "-d";
|
flagStrings[DECODE] = "-d";
|
||||||
flagStrings[INPUT_FILE] = "-i";
|
flagStrings[INPUT_FILE] = "-i";
|
||||||
@@ -225,6 +228,34 @@ std::string runAtbash(std::ifstream& infile, bool encode){
|
|||||||
return cipherString;
|
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
|
//Returns the correct function for the flags that are set
|
||||||
Fn getCipher(const bool cipherFlags[]){
|
Fn getCipher(const bool cipherFlags[]){
|
||||||
if(cipherFlags[CAESAR]){
|
if(cipherFlags[CAESAR]){
|
||||||
@@ -239,6 +270,9 @@ Fn getCipher(const bool cipherFlags[]){
|
|||||||
else if(cipherFlags[ATBASH]){
|
else if(cipherFlags[ATBASH]){
|
||||||
return runAtbash;
|
return runAtbash;
|
||||||
}
|
}
|
||||||
|
else if(cipherFlags[MORSE]){
|
||||||
|
return runMorse;
|
||||||
|
}
|
||||||
//If it didn't trip one of the flags, there was an error before this
|
//If it didn't trip one of the flags, there was an error before this
|
||||||
else{
|
else{
|
||||||
std::cout << "There was an error selecting the appropriate function";
|
std::cout << "There was an error selecting the appropriate function";
|
||||||
|
|||||||
1
main.cpp
1
main.cpp
@@ -11,6 +11,7 @@
|
|||||||
#include "Headers/Playfair.hpp"
|
#include "Headers/Playfair.hpp"
|
||||||
#include "Headers/Vigenere.hpp"
|
#include "Headers/Vigenere.hpp"
|
||||||
#include "Headers/Atbash.hpp"
|
#include "Headers/Atbash.hpp"
|
||||||
|
#include "Headers/Morse.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user