mirror of
https://bitbucket.org/Mattrixwv/cipherstream.git
synced 2025-12-07 02:43:56 -05:00
90 lines
2.2 KiB
C++
90 lines
2.2 KiB
C++
//Ciphers/main.cpp
|
|
//Matthew Ellison
|
|
// Created: 4-25-18
|
|
//Modified: 5-2-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 "Headers/Morse.hpp"
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
|
|
///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 <fstream>
|
|
|
|
|
|
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(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
|