u_char cisco_decrypt(void) { u_char retval; time_t start, stop; tty_init(); time(&start); /* check if the arg is a valid md5 cisco IOS password */ if (cisco_is_ios_md5crypt(usr_opt.decryptopt.cipher)) cipher_engine = cisco_ios_cipher; /* check if the arg is a valid md5 PIX password */ else if (cisco_is_pix_md5crypt(usr_opt.decryptopt.cipher)) cipher_engine = cisco_pix_cipher; else tty_error(ERR_USAGE, "neither a Cisco IOS nor a PIX password -- `%s'", usr_opt.decryptopt.cipher); retval = (usr_opt.action == decrypt_wl || usr_opt.action == resume_wl) ? wordlist() : bruteforce(); time(&stop); if (usr_opt.verbose) tty_message("scan time: %g second(s)\n\n", difftime(stop, start)); return retval; }
std::string TrezorCrypto::toWords(const OTPassword& seed) const { std::string wordlist( ::mnemonic_from_data( static_cast<const uint8_t*>(seed.getMemory()), seed.getMemorySize())); return wordlist; }
void WordlistDialog::on_okbutton() { // Save settings in the configuration. extern Settings *settings; settings->genconfig.wordlist_process_general_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_wordlist))); settings->genconfig.wordlist_general_asterisk_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_asterisk_general))); settings->genconfig.wordlist_general_asterisk_first_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_general_first_time))); settings->genconfig.wordlist_process_hebrew_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_hebrew_wordlist))); settings->genconfig.wordlist_hebrew_asterisk_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_asterisk_hebrew))); settings->genconfig.wordlist_hebrew_asterisk_first_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_hebrew_firsttime))); settings->genconfig.wordlist_process_greek_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_greek_wordlist))); settings->genconfig.wordlist_greek_asterisk_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_asterisk_greek))); settings->genconfig.wordlist_greek_asterisk_first_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_greek_first_time))); settings->genconfig.wordlist_process_index_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_index))); settings->genconfig.wordlist_index_asterisk_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_asterisk_index))); settings->genconfig.wordlist_index_asterisk_first_set(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(checkbutton_index_first_time))); // Run the three word lists, and collect their messages. vector < ustring > messages; if (settings->genconfig.wordlist_process_general_get()) { Wordlist wordlist(wltGeneral); wordlist.run(messages); } if (settings->genconfig.wordlist_process_hebrew_get()) { Wordlist wordlist(wltHebrew); wordlist.run(messages); } if (settings->genconfig.wordlist_process_greek_get()) { Wordlist wordlist(wltGreek); wordlist.run(messages); } if (settings->genconfig.wordlist_process_index_get()) { Wordlist wordlist(wltIndex); wordlist.run(messages); } // Display messages. if (!messages.empty()) { ustring message; for (unsigned int i = 0; i < messages.size(); i++) { message.append(messages[i] + "\n"); } gtkw_dialog_info(wordlistdialog, message.c_str()); } }
int main(int argc, char **argv) { Node root; Node *start = nullptr; stopwatch("start"); //initial tree: std::ifstream wordlist("wordlist.asc"); std::string word; while (std::getline(wordlist, word)) { Node *at = &root; for (auto c : word) { auto f = at->insert(std::make_pair(c, nullptr)).first; if (f->second == NULL) { f->second = new Node(); f->second->parent = at; f->second->depth = f->second->parent->depth + 1; } at = f->second; } assert(at); assert(at->terminal == false); at->terminal = true; if (word == "portmanteau") { start = at; } } assert(start); stopwatch("read"); //set rewind pointers: { std::vector< Node * > layer; layer.push_back(&root); while (!layer.empty()) { std::vector< Node * > next_layer; for (auto n : layer) { //update rewind pointers for children based on current rewind pointer. for (auto cn : *n) { next_layer.emplace_back(cn.second); //rewind: Node *r = n->rewind; while (r != nullptr) { assert(r != nullptr); auto f = r->find(cn.first); if (f != r->end()) { //great, can extend this rewind: r = f->second; break; } else { //have to rewind further: r = r->rewind; } } assert(n == &root || r != nullptr); //for everything but the root, rewind should always hit root and bounce down if (r == nullptr) r = &root; cn.second->rewind = r; } } layer = next_layer; } } { //dump some info about the tree: uint32_t nodes = 0; uint32_t edges = 0; uint32_t rewinds = 0; uint32_t terminal = 0; uint32_t steps = 0; std::function< void(Node *) > count = [&](Node *n) { nodes += 1; if (n->rewind) rewinds += 1; if (n->terminal) terminal += 1; for (auto &c : *n) { steps += 1; edges += 1; if (c.first != '\0') { count(c.second); } } //add valid next steps from rewind pointers: if (n->terminal) { for (Node *r = n->rewind; r != &root; r = r->rewind) { assert(r); steps += r->size(); } } }; count(&root); std::cout << "Built tree with " << nodes << " nodes and " << edges << " edges." << std::endl; std::cout << "Have " << terminal << " terminal nodes." << std::endl; std::cout << "Have " << rewinds << " rewind pointers." << std::endl; std::cout << "Have " << steps << " 'next step' edges (includes rewinds at terminals)." << std::endl; } //set indices: std::vector< Node * > nodes; uint32_t adjacencies = 0; uint32_t children = 0; { std::function< void(Node *) > index = [&](Node *n) { n->index = nodes.size(); nodes.emplace_back(n); children += n->size(); adjacencies += n->size(); //add valid next steps from rewind pointers: if (n->terminal) { for (Node *r = n->rewind; r != &root; r = r->rewind) { assert(r); adjacencies += r->size(); } } for (auto cn : *n) { index(cn.second); } }; index(&root); } for (auto n : nodes) { if (n->terminal && n->size() == 0) n->maximal = true; } { uint32_t maximal = 0; for (auto n : nodes) { if (n->maximal) ++maximal; } std::cout << "Have " << maximal << " maximal words based on child counting." << std::endl; } for (auto n : nodes) { if (n->rewind) n->rewind->maximal = false; } { uint32_t maximal = 0; for (auto n : nodes) { if (n->maximal) ++maximal; } std::cout << "Have " << maximal << " maximal words after rewind culling." << std::endl; } //okay, a valid step is: // - (at any node) a marked next letter for this node // - (at a terminal node) a marked next letter for some [non-root!] rewind of this node Graph graph; graph.resize(nodes.size(), adjacencies, children); { auto adj_start = graph.adj_start; auto adj = graph.adj; auto adj_char = graph.adj_char; auto child_start = graph.child_start; auto child = graph.child; auto child_char = graph.child_char; for (auto const &n : nodes) { assert(&n - &nodes[0] == n->index); *(adj_start++) = adj - graph.adj; *(child_start++) = child - graph.child; std::vector< std::pair< char, Node * > > valid(n->begin(), n->end()); std::stable_sort(valid.begin(), valid.end()); for (auto v : valid) { *(child_char++) = v.first; *(child++) = v.second->index; } if (n->terminal) { for (Node *r = n->rewind; r != &root; r = r->rewind) { assert(r); valid.insert(valid.end(), r->begin(), r->end()); } } std::stable_sort(valid.begin(), valid.end()); for (auto v : valid) { *(adj_char++) = v.first; *(adj++) = v.second->index; } } *(adj_start++) = adj - graph.adj; *(child_start++) = child - graph.child; assert(adj == graph.adj + adjacencies); assert(adj_char == graph.adj_char + adjacencies); assert(adj_start == graph.adj_start + nodes.size() + 1); assert(child == graph.child + children); assert(child_char == graph.child_char + children); assert(child_start == graph.child_start + nodes.size() + 1); } { auto depth = graph.depth; auto maximal = graph.maximal; auto parent = graph.parent; auto rewind = graph.rewind; for (uint32_t i = 0; i < nodes.size(); ++i) { assert(nodes[i]->index == i); *(depth++) = nodes[i]->depth; *(maximal++) = nodes[i]->maximal; if (nodes[i]->parent) { *(parent++) = nodes[i]->parent->index; } else { assert(i == 0); *(parent++) = -1U; } if (nodes[i]->rewind) { *(rewind++) = nodes[i]->rewind->index; } else { *(rewind++) = -1U; } } assert(depth == graph.depth + nodes.size()); assert(maximal == graph.maximal + nodes.size()); assert(parent == graph.parent + nodes.size()); assert(rewind == graph.rewind + nodes.size()); } stopwatch("build"); graph.write("wordlist.graph"); stopwatch("write"); return 0; }