From 4f4444a62ada09d8af878cf13d34459cf68631e2 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 15 Jan 2020 12:03:14 +0100 Subject: [PATCH 1/4] string: add l33twords() function. --- src/string.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/string.h | 2 ++ 2 files changed, 51 insertions(+) diff --git a/src/string.cpp b/src/string.cpp index a8c4e99..89ff7b9 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -78,3 +78,52 @@ std::string& base58_strip(std::string &str) { ), str.end()); return str; } + +static bool is_l33t(char ch, char& r) { + + // '1', '2', '3', '4', '5', '6', '7', '8', '9' + static char alphabet[9] = { 'l', 'z', 'e', 'a', 's', 'G', 't', 'B', 'g' }; + + for(int i = 0; i < sizeof(alphabet) / sizeof(char); i++) { + + if (ch == alphabet[i]) { + r = '1' + i; + return true; + } + } + return false; +} + +static void _l33t(strlist_t& list, const std::string& a, int pos) { + + // Find the next character to be replaced. + for(int i = pos; i < a.length(); i++) { + + char ch; + if (is_l33t(a[i], ch)) { + // create a new string and replace the character. + std::string b = a; + b[i] = ch; + + // Store the new string as the result. + list.push_back(b); + + // Perform the same algorithm for both strings + // at the next position. + _l33t(list, a, i + 1); + _l33t(list, b, i + 1); + break; + } + } +} + +strlist_t l33twords(const std::string& str) { + + strlist_t list; + + // Store the original string as the first in list. + list.push_back(str); + + _l33t(list, str, 0); + return list; +} diff --git a/src/string.h b/src/string.h index 38c0440..0358667 100644 --- a/src/string.h +++ b/src/string.h @@ -41,4 +41,6 @@ std::string& trim(std::string& str); std::string& base58_strip(std::string &str); +strlist_t l33twords(const std::string& str); + #endif /* STRING_H */ From 5bc3335d541f53570cf59d3ebc2fc69089f8405b Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 15 Jan 2020 12:30:49 +0100 Subject: [PATCH 2/4] string: adding strjoin() function --- src/string.cpp | 15 +++++++++++++++ src/string.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/src/string.cpp b/src/string.cpp index 89ff7b9..d5af6f8 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -46,6 +46,21 @@ strlist_t strsplit(const std::string& str, const std::string& delim) { return r; } +std::string strjoin(const strlist_t& list, const std::string& delim) { + + std::string out; + + for(const std::string& item : list) { + out += item + delim; + } + + if (out.length() > 0) { + out.erase(out.end() - delim.length()); + } + + return out; +} + std::string& strtolower(std::string& str) { std::transform(str.begin(), str.end(), str.begin(), [](unsigned char c){ return std::tolower(c); }); return str; diff --git a/src/string.h b/src/string.h index 0358667..98c1c8a 100644 --- a/src/string.h +++ b/src/string.h @@ -33,6 +33,8 @@ strlist_t strsplitwords(const std::string& str, const std::string& delim = ","); strlist_t strsplit(const std::string& str, const std::string& delim); +std::string strjoin(const strlist_t& list, const std::string& delim); + std::string& strtolower(std::string& str); std::string& rtrim(std::string& str); From 237fc4e4afc0893519a571f305edd107e0181ea9 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 15 Jan 2020 12:32:35 +0100 Subject: [PATCH 3/4] src/main.cpp: call strjoin(words) instead of printing "search" directly. --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index ffa54da..87144ec 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,7 +68,7 @@ void cmd_search(int argc, char **argv) { n_thread_argv; std::cout << "Searching for " << n - << " keys containing: " << search + << " keys containing: " << strjoin(words, ",") n_thread_outp << std::endl; From f6e4603cbe2c8a3bf5ca5fde78597a9d8ead6ff5 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Wed, 15 Jan 2020 12:33:11 +0100 Subject: [PATCH 4/4] src/main.cpp: implement "--l33t" flag. --- src/main.cpp | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index 87144ec..3c67bbc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,9 @@ #include "ec.h" #include "key_search.h" +// Command line options. +bool option_l33t = false; + #ifdef HAVE_THREADS #define n_thread_decl int n_threads = std::thread::hardware_concurrency() #define n_thread_argv \ @@ -56,7 +59,18 @@ void cmd_search(int argc, char **argv) { int n = 100; n_thread_decl; std::string search(argv[0]); - strlist_t words = strsplitwords(strtolower(base58_strip(search))); + strlist_t words; + + if (option_l33t) { + strlist_t tmp = strsplitwords(search); + for(int i = 0; i < tmp.size(); i++) { + strlist_t list = l33twords(base58_strip(tmp[i])); + words.reserve(words.size() + list.size()); + words.insert(words.end(), list.begin(), list.end()); + } + } else { + words = strsplitwords(strtolower(base58_strip(search))); + } if (argc > 1) { n = atoi(argv[1]); @@ -105,6 +119,12 @@ int main(int argc, char **argv) { return 0; } + if (!strcmp(argv[1], "--l33t")) { + option_l33t = true; + argc--; + argv = &argv[1]; + } + if (!strcmp(argv[1], "search")) { if (argc < 3) { std::cout << "You must specify a word list." << std::endl;