// Hex code solver for a file containing encoded text, one message per line. void fileSolver(const std::string& filePath) { std::vector<std::string> messages; // Read in the strings std::ifstream inFile(filePath); if (inFile.is_open()) { std::string line; while ( std::getline(inFile, line) ) { messages.push_back(line); } inFile.close(); } else { std::cout << "Unable to open file \"" << filePath << "\". Please check your inputs and try again." << std::endl; } // Decode each message std::vector<std::future<std::array<std::string, 2>>> futures; for (auto message : messages) { futures.push_back(std::async(std::launch::async, [](std::string encoded) { std::array<std::string, 2> result; result[0] = encoded; result[1] = stringSolver(encoded); return result; }, message)); } // Print out the original message and the best decoded message for (auto &f : futures) { auto temp = f.get(); std::cout << "Solving cyphertext '" << temp[1] << "'." << std::endl; std::string systemString("bin/caesarSolver.exe -s \"" + temp[1] + "\""); system(systemString.c_str()); } }
int main(int argc, char* argv[]) { // Parse input arguments std::string out; auto command = parseCLI(argc, argv, out); switch (command) { // If file is passed, read file case SOLVE_FILE: std::cout << "Solving cyphertext in file '" << out << "'." << std::endl; fileSolver(out); break; // If text is passed, solve the text case SOLVE_STRING: { std::cout << "Solving cyphertext '" << out << "'." << std::endl; auto temp = stringSolver(out); std::string systemString("bin/caesarSolver.exe -s \"" + temp + "\""); system(systemString.c_str()); break; } // Invalid CLI params; display help text case UNDEFINED: default: //displayCliHelp(); break; } return 0; }
void ShowHelpDialog(const char* msg, const char* url, const char* type) { std::string zenityString; zenityString += "--text="; zenityString += msg; execlp("zenity", "zenity", type, zenityString.c_str(), NULL); execlp("kdialog", "kdialog", type, msg, NULL); execlp("gxmessage", "gxmessage", "-buttons", "GTK_STOCK_OK", "-center", "-default", "GTK_STOCK_OK", "-title", "Information", "-wrap", msg, NULL); execlp("gmessage", "gmessage", "-buttons", "GTK_STOCK_OK", "-center", "-default", "OK", "-title", "Information", "-wrap", msg, NULL); execlp("xmessage", "xmessage", "-center", msg, NULL); fprintf(stderr, "%s\n", msg); if (url) { std::string systemString("xdg-open "); systemString += url; system(systemString.c_str()); } }