diff --git a/key.txt b/key.txt new file mode 100644 index 0000000..f01fd5d --- /dev/null +++ b/key.txt @@ -0,0 +1 @@ +A0 7C 3D 99 FA 00 02 46 97 33 73 50 31 7C D3 DC \ No newline at end of file diff --git a/main.cpp b/main.cpp index 3555284..325dfde 100644 --- a/main.cpp +++ b/main.cpp @@ -1,12 +1,15 @@ #include "aes.hpp" #include +#include #include #include "profiler.hpp" using namespace std; +uint8_t key[16]; + string prompt(char separator = '>') { PROFILER_RECORD; @@ -25,13 +28,12 @@ void print_help() { PROFILER_RECORD; // TODO Verify whether there are more/less commands - cout << "The following commands are available: help, login, exit" << endl; + cout << "The following commands are available: help, login, register, exit" << endl; } void login() { PROFILER_RECORD; - uint8_t key[16] = {0xA0,0x7C,0x3D,0x99,0xFA,0x00,0x02,0x46,0x97,0x33,0x73,0x50,0x31,0x7C,0xD3,0xDC}; // TODO Load me from a file cout << "Username"; string username = prompt(':'); cout << "Password"; @@ -50,6 +52,12 @@ void login() // TODO Validate encrypted password } +void register_user() +{ + PROFILER_RECORD; + cout << "Registration is currently unavailable" << endl; +} + bool execute_command(const string &input) { PROFILER_RECORD; @@ -62,19 +70,41 @@ bool execute_command(const string &input) { login(); } + else if (input == "register") + { + register_user(); + } else if (input == "help") { print_help(); } - else if (!profiler.command_line(input)) + else if (input == "profiler_print") { - cout << "Invalid command '" << input << "'" << endl; + profiler.print(); } + else if (input == "profiler_reset") + { + profiler.reset(); + } + cout << "Invalid command '" << input << "'" << endl; return true; } +void load_key() +{ + PROFILER_RECORD; + ifstream file("key.txt"); + string line; + getline(file, line); + for (int i = 0;i < 16;i++) + { + key[i] = stoi(line.substr(3 * i, 2), 0, 16); + } +} + int main(int argc, char **argv) { PROFILER_RECORD; + load_key(); cout << "Welcome to the Secutech customer portal." << endl; cout << "How can we help you today? (type 'help' for help)" << endl; string input; diff --git a/profiler.cpp b/profiler.cpp index 93a9d22..8a077c1 100644 --- a/profiler.cpp +++ b/profiler.cpp @@ -1,11 +1,9 @@ #include "profiler.hpp" #include -#include #include using namespace std; -using std::string; Profiler profiler; @@ -19,22 +17,12 @@ void Profiler::reset() calls.clear(); } -bool Profiler::command_line(const string &input) +void Profiler::print() const { - if (input == "profiler_print") + for (auto it = this->calls.begin();it != this->calls.end();it++) { - for (auto it = this->calls.begin();it != this->calls.end();it++) - { - ostringstream out; - out << left << setw(25) << it->first << right << setw(5) << it->second; - cout << out.str() << endl; - } - return true; + ostringstream out; + out << left << setw(25) << it->first << right << setw(5) << it->second; + cout << out.str() << endl; } - if (input == "profiler_reset") - { - this->reset(); - return true; - } - return false; } diff --git a/profiler.hpp b/profiler.hpp index 9f3b8bb..77d50de 100644 --- a/profiler.hpp +++ b/profiler.hpp @@ -10,7 +10,7 @@ public: std::map calls; void record_function_call(const char *function_name); void reset(); - bool command_line(const std::string &input); + void print() const; }; #define PROFILER_RECORD profiler.record_function_call(__func__)