mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-06-18 04:00:03 +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:
parent
8c8d88c631
commit
075144c72b
4 changed files with 26 additions and 14 deletions
|
|
@ -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++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <word_list> appears in <key>'s public key.
|
||||
// returns true if a word was found (stored in <word>), 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 <result>), 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 */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue