1
0
Fork 0
mirror of https://github.com/eosswedenorg/antelope-keygen synced 2026-07-03 11:53:41 +02:00

search: define a key_result struct and store position and length in public key for the word found.

This commit is contained in:
Henrik Hautakoski 2020-01-16 14:04:54 +01:00
parent 8c8d88c631
commit 075144c72b
4 changed files with 26 additions and 14 deletions

View file

@ -35,10 +35,10 @@ void KeySearch::_search_linear(size_t n) {
struct ec_keypair pair; struct ec_keypair pair;
while (count < n) { while (count < n) {
std::string word; struct key_result res;
ec_generate_key(&pair); ec_generate_key(&pair);
if (key_contains_word(&pair, m_words, word)) { if (key_contains_word(&pair, m_words, &res)) {
key_search_result(word, &pair); key_search_result(&pair, &res);
count++; count++;
} }
} }

View file

@ -3,22 +3,29 @@
#include "WIF.h" #include "WIF.h"
#include "key_search_helpers.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 << "----" << std::endl;
std::cout << "Found: " << word << 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" // skip first 3 chars, as those are always "EOS"
std::string pubstr = wif_pub_encode(key->pub).substr(3); std::string pubstr = wif_pub_encode(key->pub).substr(3);
strtolower(pubstr); strtolower(pubstr);
for(auto const& w: word_list) { for(auto const& w: word_list) {
if (pubstr.find(w) != std::string::npos) { size_t p = pubstr.find(w);
word = w; if (p != std::string::npos) {
result->pos = p + 3;
result->len = w.length();
return true; return true;
} }
} }

View file

@ -27,10 +27,15 @@
#include "string.h" #include "string.h"
#include "ec.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 <word_list> appears in <key>'s public key. // Check if any word in <word_list> appears in <key>'s public key.
// returns true if a word was found (stored in <word>), false otherwise. // returns true if a word was found (stored in <result>), false otherwise.
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);
#endif /* KEY_SEARCH_HELPERS_H */ #endif /* KEY_SEARCH_HELPERS_H */

View file

@ -21,10 +21,10 @@ static void _thr_proc(const strlist_t& word_list) {
struct ec_keypair pair; struct ec_keypair pair;
while (g_count < g_max) { while (g_count < g_max) {
std::string word; struct key_result res;
ec_generate_key(&pair); 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 // Guard output with mutex, so we don't get
// interrupted mid write and can write to g_count safely. // 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. // Update count and print result.
g_count++; g_count++;
key_search_result(word, &pair); key_search_result(&pair, &res);
} }
} }
} }