diff --git a/src/key_search.cpp b/src/key_search.cpp index e55b808..ddff617 100644 --- a/src/key_search.cpp +++ b/src/key_search.cpp @@ -35,10 +35,10 @@ void KeySearch::_search_linear(size_t n) { struct ec_keypair pair; while (count < n) { - std::string word; + struct key_result res; ec_generate_key(&pair); - if (key_contains_word(&pair, m_words, word)) { - key_search_result(word, &pair); + if (key_contains_word(&pair, m_words, &res)) { + key_search_result(&pair, &res); count++; } } diff --git a/src/key_search_helpers.cpp b/src/key_search_helpers.cpp index 7b6cf2c..827a88e 100644 --- a/src/key_search_helpers.cpp +++ b/src/key_search_helpers.cpp @@ -3,22 +3,29 @@ #include "WIF.h" #include "key_search_helpers.h" -void key_search_result(const std::string& word, const struct ec_keypair* pair) { +void key_search_result(const struct ec_keypair* key, const struct key_result* result) { + + std::string pub = wif_pub_encode(key->pub); + std::string word = pub.substr(result->pos, result->len); std::cout << "----" << std::endl; std::cout << "Found: " << word << std::endl; - wif_print_key(pair); + + std::cout << "Public: " << pub << std::endl; + std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl; } -bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, std::string& word) { +bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result) { // skip first 3 chars, as those are always "EOS" std::string pubstr = wif_pub_encode(key->pub).substr(3); strtolower(pubstr); for(auto const& w: word_list) { - if (pubstr.find(w) != std::string::npos) { - word = w; + size_t p = pubstr.find(w); + if (p != std::string::npos) { + result->pos = p + 3; + result->len = w.length(); return true; } } diff --git a/src/key_search_helpers.h b/src/key_search_helpers.h index 66d4291..66e7783 100644 --- a/src/key_search_helpers.h +++ b/src/key_search_helpers.h @@ -27,10 +27,15 @@ #include "string.h" #include "ec.h" -void key_search_result(const std::string& word, const struct ec_keypair* pair); +struct key_result { + size_t pos; // position where the word was found. + size_t len; // the length of the word. +}; + +void key_search_result(const struct ec_keypair* key, const struct key_result* result); // Check if any word in appears in 's public key. -// returns true if a word was found (stored in ), false otherwise. -bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, std::string& word); +// returns true if a word was found (stored in ), false otherwise. +bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result); #endif /* KEY_SEARCH_HELPERS_H */ diff --git a/src/key_search_mt.cpp b/src/key_search_mt.cpp index 3854529..881ed53 100644 --- a/src/key_search_mt.cpp +++ b/src/key_search_mt.cpp @@ -21,10 +21,10 @@ static void _thr_proc(const strlist_t& word_list) { struct ec_keypair pair; while (g_count < g_max) { - std::string word; + struct key_result res; ec_generate_key(&pair); - if (key_contains_word(&pair, word_list, word)) { + if (key_contains_word(&pair, word_list, &res)) { // Guard output with mutex, so we don't get // interrupted mid write and can write to g_count safely. @@ -39,7 +39,7 @@ static void _thr_proc(const strlist_t& word_list) { // Update count and print result. g_count++; - key_search_result(word, &pair); + key_search_result(&pair, &res); } } }