1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-06-18 04:00:03 +02:00

key_search: split key_search() function into key_search() and key_search_n()

This commit is contained in:
Henrik Hautakoski 2020-01-10 09:27:49 +01:00
parent f4e2b1e162
commit 77d63a5c36
3 changed files with 29 additions and 15 deletions

View file

@ -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++;
}
}
}

View file

@ -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 */

View file

@ -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) {