From bae37212111c774ed805a61d8ea70ce525c138b5 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Fri, 10 Jan 2020 10:39:39 +0100 Subject: [PATCH] src/key_search_helpers.cpp: add key_contains_word() --- src/key_search_helpers.cpp | 14 ++++++++++++++ src/key_search_helpers.h | 6 +++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/key_search_helpers.cpp b/src/key_search_helpers.cpp index 869e64f..82d625e 100644 --- a/src/key_search_helpers.cpp +++ b/src/key_search_helpers.cpp @@ -9,3 +9,17 @@ void key_search_result(const std::string& word, const struct ec_keypair* pair) { std::cout << "Found: " << word << std::endl; wif_print_key(pair); } + +bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, std::string& word) { + + std::string 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; +} diff --git a/src/key_search_helpers.h b/src/key_search_helpers.h index 70ee1b4..66d4291 100644 --- a/src/key_search_helpers.h +++ b/src/key_search_helpers.h @@ -24,9 +24,13 @@ #ifndef KEY_SEARCH_HELPSER_H #define KEY_SEARCH_HELPERS_H -#include +#include "string.h" #include "ec.h" void key_search_result(const std::string& word, const struct ec_keypair* pair); +// Check if any word in appears in 's public key. +// returns true if a word was found (stored in ), false otherwise. +bool key_contains_word(const struct ec_keypair* key, const strlist_t& word_list, std::string& word); + #endif /* KEY_SEARCH_HELPERS_H */