//Name:Reece Warner //Date:4/24/24 //Assignment:Homework2 #include "Base64Conversion.hpp" constexpr short ARG_COUNT = 4; bool Worker(); bool Worker(char** argv); int main(const int argc, char* argv[]) { if (argc == ARG_COUNT) { Worker(argv); } else { Worker(); } return 0; } bool Worker() { bool success = false; char* MyEncodedCharArray = nullptr; const char* MyFile = nullptr; const char* Destination = nullptr; char* buffer = nullptr; size_t size = 0; char Option = '\0'; do { Prompts("!Welcome to the Base64 Encoding/Decoding Menu!\n\ne)Base64 Encode Your File\nd)Decode Your Encoded File\nf)Exit\n\n"); std::cin >> Option; switch (Option) { case 'e': MyFile = InputFileName("What is the name of the file you wish to encode?: "); Destination = InputFileName("\nWhat is the name of the file that you wish to save the encoded information?: "); size = SizeOfFile(MyFile); buffer = new char[size]; buffer = ReadFileAsBinary(MyFile, buffer, size); success = WriteTextToFile(Destination, Base64Encode(buffer, size)); delete[] buffer; return true; case 'd': MyFile = InputFileName("What is the name of the file you wish to decode?: "); Destination = InputFileName("\nWhat is the name of the file you wish to save the decoded information?: "); size = SizeOfFile(MyFile); buffer = new char[size]; ReadTextFromFile(MyFile, buffer); success = WriteFileFromBinary(Destination,buffer, Base64Decode(buffer, size)); return true; case'f': std::cout << "Have a great day!" << std::endl; break; default: std::cerr << "Error, invalid command option\n" << "Valid commands:\n" << "\t -e source_file.exe destination_file.exe" << "\tEncodes file in source to text in destination txt file.\n\n" << "\t-d source_file.text destination_file.exe" << "\tDecodes text in source file into the destination file.\n\n"; return false; } } while (Option != 'f'); return false; } bool Worker(char** argv) { const char* arg1 = argv[1]; const char* arg2 = argv[2]; const char* arg3 = argv[3]; char* buffer = nullptr; bool success = false; char* MyEncodedCharArray = nullptr; const size_t size = SizeOfFile(arg2); const char option = arg1[1]; switch (option) { case 'e': buffer = new char[size]; buffer = ReadFileAsBinary(arg2, buffer, size); success = WriteTextToFile(arg3, Base64Encode(buffer, size)); delete[] buffer; return success; case 'd': buffer = new char[size]; buffer = ReadTextFromFile(arg2, buffer); success = WriteFileFromBinary(arg3, buffer, Base64Decode(buffer, size)); return true; default: std::cerr << "Error, invalid command option\n" << "Valid commands:\n" << "\t -e source_file.exe destination_file.exe" << "\tEncodes file in source to text in destination txt file.\n\n" << "\t-d source_file.text destination_file.exe" << "\tDecodes text in source file into the destination file.\n\n"; return false; } }