// Name: Wesley Richelderfer // Class: CST 126 // Date: 4/27/24 // Assignment: Homework 2 #include #include #include "helpers.hpp" #include "Base64Converter.hpp" using std::string; constexpr short ARG_COUNT = 4; bool Worker(); bool Worker(char** argv); int main (const int argc, char* argv[]) { if(argc == ARG_COUNT) { //run command line version Worker(argv); } //console app version return Worker(); } bool Worker() { //files and choice char option; string destination; string source; //variables for switch statement bool success; vector buffer; string product; size_t size = 0; cout << "Would you like to encode or decode? (e or d): "; cin >> option; cout << "\n\nWhat is the source file name? "; cin >> source; cout << "\n\nWhat is the destination file name? "; cin >> destination; const char* arg2 = source.c_str(); const char* arg3 = destination.c_str(); switch (option) { case 'e': buffer = ReadFileAsBinary(arg2, buffer); size = buffer.size(); product = Base64Encode(&buffer[0], size); success = WriteTextToFile(arg3, product); return success; case 'd': ReadTextFromFile(arg2, product); buffer = Base64Decoder(product); success = WriteFileFromBinary(arg3, buffer); return success; default: std::cerr << "Invalid command option\n" << "Valid commands:\n" << "\t-e source_file.exe destination_file.exe" << "\t\tEncodes file in source into text in destination txt file." << "\t-d source_file.txt destination_file.exe" << "\t\tDecodes text in source file into the destination file.\n\n"; return false; } } bool Worker(char** argv) { //files and choice const char* arg1 = argv[1]; //-e -d const char* arg2 = argv[2]; //source file name const char* arg3 = argv[3]; //destination file name const char option = arg1[1]; //e or d //variables for switch statement bool success; vector buffer; string product; size_t size = 0; switch(option) { case 'e': buffer = ReadFileAsBinary(arg2, buffer); size = buffer.size(); product = Base64Encode(&buffer[0], size); success = WriteTextToFile(arg3, product); return success; case 'd': ReadTextFromFile(arg2, product); buffer = Base64Decoder(product); success = WriteFileFromBinary(arg3, buffer); return success; default: std::cerr << "Invalid command option\n" << "Valid commands:\n" << "\t-e source_file.exe destination_file.exe" << "\t\tEncodes file in source into text in destination txt file." << "\t-d source_file.txt destination_file.exe" << "\t\tDecodes text in source file into the destination file.\n\n"; return false; } }