diff --git a/src/key_search.cpp b/src/key_search.cpp index 9286ddf..c18c015 100644 --- a/src/key_search.cpp +++ b/src/key_search.cpp @@ -25,22 +25,33 @@ static void key_result(const std::string& word, const struct ec_keypair* pair) { wif_print_key(pair); } -void key_search(strlist_t word_list, size_t n) { +bool key_search(struct ec_keypair* key, std::string& word, const strlist_t& word_list) { + + std::string pubstr; + + ec_generate_key(key); + pubstr = wif_pub_encode(key->pub); + strtolower(pubstr); + + for(auto const& w: word_list) { + if (pubstr.find(w) != std::string::npos) { + word = w; + return true; + } + } + return false; +} + +void key_search_n(const strlist_t& word_list, size_t n) { size_t count = 0; struct ec_keypair pair; while (count < n) { - std::string pubstr; - ec_generate_key(&pair); - pubstr = wif_pub_encode(pair.pub); - strtolower(pubstr); - - for(auto const& word: word_list) { - if (pubstr.find(word) != std::string::npos) { - key_result(word, &pair); - count++; - } + std::string word; + if (key_search(&pair, word, word_list)) { + key_result(word, &pair); + count++; } } } diff --git a/src/key_search.h b/src/key_search.h index 742195c..3f73e16 100644 --- a/src/key_search.h +++ b/src/key_search.h @@ -25,7 +25,10 @@ #define KEY_SEARCH_H #include "string.h" +#include "ec.h" -void key_search(strlist_t word_list, size_t n); +bool key_search(struct ec_keypair* out, std::string& word, const strlist_t& word_list); + +void key_search_n(const strlist_t& word_list, size_t n); #endif /* KEY_SEARCH_H */ diff --git a/src/main.cpp b/src/main.cpp index 84c78b7..9f334d6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -65,11 +65,11 @@ static void thread_search(const strlist_t& words, int n) { // Launch threads. for(int i = 0; i < t.size(); i++) { - t[i] = std::thread(key_search, words, d); + t[i] = std::thread(key_search_n, words, d); } // Use main thread for 1 search - key_search(words, d + m); + key_search_n(words, d + m); // Wait for all threads to compelete. for(int i = 0; i < t.size(); i++) { @@ -77,7 +77,7 @@ static void thread_search(const strlist_t& words, int n) { } } #else -#define search_func key_search +#define search_func key_search_n #endif void cmd_search(int argc, char **argv) {