mirror of
https://github.com/eosswedenorg/antelope-keygen
synced 2026-07-04 12:03:41 +02:00
refactor struct key_search_result from src/key_search_helpers.h to include/eoskeygen/key_search.h
This commit is contained in:
parent
8035e3233c
commit
a417390bb7
5 changed files with 36 additions and 32 deletions
|
|
@ -31,6 +31,13 @@ namespace eoskeygen {
|
||||||
|
|
||||||
class KeySearch
|
class KeySearch
|
||||||
{
|
{
|
||||||
|
public :
|
||||||
|
|
||||||
|
struct result {
|
||||||
|
size_t pos; // position where the word was found.
|
||||||
|
size_t len; // the length of the word.
|
||||||
|
};
|
||||||
|
|
||||||
public :
|
public :
|
||||||
// Add a word to search for.
|
// Add a word to search for.
|
||||||
void addWord(const std::string& str);
|
void addWord(const std::string& str);
|
||||||
|
|
@ -56,6 +63,10 @@ public :
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
|
// Check if any word in <word_list> appears in <key>'s public key.
|
||||||
|
// returns true if a word was found (stored in <result>), false otherwise.
|
||||||
|
bool _contains_word(const struct ec_keypair* key, struct result& result);
|
||||||
|
|
||||||
#ifdef HAVE_THREADS
|
#ifdef HAVE_THREADS
|
||||||
void _thr_proc();
|
void _thr_proc();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@
|
||||||
*/
|
*/
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <eoskeygen/crypto/ec.h>
|
#include <eoskeygen/crypto/ec.h>
|
||||||
|
#include <eoskeygen/crypto/WIF.h>
|
||||||
#include <eoskeygen/key_search.h>
|
#include <eoskeygen/key_search.h>
|
||||||
#include "key_search_helpers.h"
|
#include "key_search_helpers.h"
|
||||||
|
|
||||||
|
|
@ -63,9 +64,9 @@ void KeySearch::_search_linear(size_t n) {
|
||||||
struct ec_keypair pair;
|
struct ec_keypair pair;
|
||||||
|
|
||||||
while (count < n) {
|
while (count < n) {
|
||||||
struct key_result res;
|
struct result res;
|
||||||
ec_generate_key(&pair);
|
ec_generate_key(&pair);
|
||||||
if (key_contains_word(&pair, m_words, &res)) {
|
if (_contains_word(&pair, res)) {
|
||||||
key_search_result(&pair, &res, m_dict);
|
key_search_result(&pair, &res, m_dict);
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
@ -85,4 +86,21 @@ void KeySearch::find(size_t num_results) {
|
||||||
_search_linear(num_results);
|
_search_linear(num_results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool KeySearch::_contains_word(const struct ec_keypair* key, struct 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: m_words) {
|
||||||
|
size_t p = pubstr.find(w);
|
||||||
|
if (p != std::string::npos) {
|
||||||
|
result.pos = p + 3;
|
||||||
|
result.len = w.length();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace eoskeygen
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ static size_t highlight(console::Color color, const std::string& str, size_t pos
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void key_search_result(const struct ec_keypair* key, const struct key_result* result, const Dictionary& dict) {
|
void key_search_result(const struct ec_keypair* key, const struct KeySearch::result* result, const Dictionary& dict) {
|
||||||
|
|
||||||
std::string pub = wif_pub_encode(key->pub);
|
std::string pub = wif_pub_encode(key->pub);
|
||||||
Dictionary::search_result_t dict_res = dict.search(pub);
|
Dictionary::search_result_t dict_res = dict.search(pub);
|
||||||
|
|
@ -66,21 +66,4 @@ void key_search_result(const struct ec_keypair* key, const struct key_result* re
|
||||||
<< "Private: " << wif_priv_encode(key->secret) << std::endl;
|
<< "Private: " << wif_priv_encode(key->secret) << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
|
||||||
size_t p = pubstr.find(w);
|
|
||||||
if (p != std::string::npos) {
|
|
||||||
result->pos = p + 3;
|
|
||||||
result->len = w.length();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace eoskeygen
|
} // namespace eoskeygen
|
||||||
|
|
|
||||||
|
|
@ -26,21 +26,13 @@
|
||||||
|
|
||||||
#include <eoskeygen/core/string.h>
|
#include <eoskeygen/core/string.h>
|
||||||
#include <eoskeygen/crypto/types.h>
|
#include <eoskeygen/crypto/types.h>
|
||||||
|
#include <eoskeygen/key_search.h>
|
||||||
|
|
||||||
namespace eoskeygen {
|
namespace eoskeygen {
|
||||||
|
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
|
|
||||||
struct key_result {
|
void key_search_result(const struct ec_keypair* key, const struct KeySearch::result* result, const Dictionary& dict);
|
||||||
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, const Dictionary& dict);
|
|
||||||
|
|
||||||
// Check if any word in <word_list> appears in <key>'s public key.
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
} // namespace eoskeygen
|
} // namespace eoskeygen
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,10 @@ void KeySearch::_thr_proc() {
|
||||||
struct ec_keypair pair;
|
struct ec_keypair pair;
|
||||||
|
|
||||||
while (g_count < g_max) {
|
while (g_count < g_max) {
|
||||||
struct key_result res;
|
struct result res;
|
||||||
|
|
||||||
ec_generate_key(&pair);
|
ec_generate_key(&pair);
|
||||||
if (key_contains_word(&pair, m_words, &res)) {
|
if (_contains_word(&pair, 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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue