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

key_search_helpers: in key_search_result() pass a dictionary object and highlight words from it.

This commit is contained in:
Henrik Hautakoski 2020-02-17 15:12:34 +01:00
parent f9aab4033e
commit 912ae83684
2 changed files with 33 additions and 10 deletions

View file

@ -22,27 +22,48 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <iostream> #include <iostream>
#include "core/dictionary.h"
#include "WIF.h" #include "WIF.h"
#include "console.h" #include "console.h"
#include "key_search_helpers.h" #include "key_search_helpers.h"
namespace eoskeygen { namespace eoskeygen {
void key_search_result(const struct ec_keypair* key, const struct key_result* result) { static size_t highlight(console::Color color, const std::string& str, size_t pos, size_t len) {
std::cout << console::fg(color, console::bold)
<< str.substr(pos, len)
<< console::reset;
return len;
}
void key_search_result(const struct ec_keypair* key, const struct key_result* result, const Dictionary& dict) {
std::string pub = wif_pub_encode(key->pub); std::string pub = wif_pub_encode(key->pub);
std::string word = pub.substr(result->pos, result->len); Dictionary::search_result_t dict_res = dict.search(pub);
std::cout << "----" << std::endl; std::cout << "----" << std::endl;
std::cout << "Found: " << word << std::endl; std::cout << "Found: " << pub.substr(result->pos, result->len) << std::endl;
std::cout << "Public: " std::cout << "Public: EOS";
<< pub.substr(0, result->pos) for(size_t i = 3; i < pub.length(); ) {
<< console::fg(console::red, console::bold) << word << console::reset
<< pub.substr(result->pos + result->len)
<< std::endl;
std::cout << "Private: " << wif_priv_encode(key->secret) << std::endl; if (i == result->pos) {
i += highlight(console::red, pub, result->pos, result->len);
continue;
}
auto p = dict_res.find(i);
if (p != dict_res.end()) {
i += highlight(console::blue, pub, p->first, p->second);
continue;
}
std::cout << pub[i++];
}
std::cout << 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) { bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, struct key_result *result) {

View file

@ -29,12 +29,14 @@
namespace eoskeygen { namespace eoskeygen {
class Dictionary;
struct key_result { struct key_result {
size_t pos; // position where the word was found. size_t pos; // position where the word was found.
size_t len; // the length of the word. size_t len; // the length of the word.
}; };
void key_search_result(const struct ec_keypair* key, const struct key_result* result); 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. // 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. // returns true if a word was found (stored in <result>), false otherwise.