mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-02 11:43:40 +02:00
key_search: split key_search() function into key_search() and key_search_n()
This commit is contained in:
parent
f4e2b1e162
commit
77d63a5c36
3 changed files with 29 additions and 15 deletions
|
|
@ -25,22 +25,33 @@ static void key_result(const std::string& word, const struct ec_keypair* pair) {
|
||||||
wif_print_key(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;
|
size_t count = 0;
|
||||||
struct ec_keypair pair;
|
struct ec_keypair pair;
|
||||||
|
|
||||||
while (count < n) {
|
while (count < n) {
|
||||||
std::string pubstr;
|
std::string word;
|
||||||
ec_generate_key(&pair);
|
if (key_search(&pair, word, word_list)) {
|
||||||
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);
|
key_result(word, &pair);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,10 @@
|
||||||
#define KEY_SEARCH_H
|
#define KEY_SEARCH_H
|
||||||
|
|
||||||
#include "string.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 */
|
#endif /* KEY_SEARCH_H */
|
||||||
|
|
|
||||||
|
|
@ -65,11 +65,11 @@ static void thread_search(const strlist_t& words, int n) {
|
||||||
|
|
||||||
// Launch threads.
|
// Launch threads.
|
||||||
for(int i = 0; i < t.size(); i++) {
|
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
|
// Use main thread for 1 search
|
||||||
key_search(words, d + m);
|
key_search_n(words, d + m);
|
||||||
|
|
||||||
// Wait for all threads to compelete.
|
// Wait for all threads to compelete.
|
||||||
for(int i = 0; i < t.size(); i++) {
|
for(int i = 0; i < t.size(); i++) {
|
||||||
|
|
@ -77,7 +77,7 @@ static void thread_search(const strlist_t& words, int n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define search_func key_search
|
#define search_func key_search_n
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void cmd_search(int argc, char **argv) {
|
void cmd_search(int argc, char **argv) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue