You are viewing a single comment's thread. Return to all comments →
C++
struct Cracker { vector<string> pws; string login; vector<vector<size_t>> heads; vector<bool> visited; string result; Cracker(vector<string> const& pws, string const& login) : pws(pws), login(login), heads(login.size()), visited(login.size()) { size_t i = 0, j = 0; for (i = 0; i < pws.size(); i++) for (j = 0; (j=login.find(pws[i], j))!=string::npos;) heads[j++].push_back(i); deque<size_t> pid; if (dfs(0, pid)) for (i = 0; i < pid.size(); i++) result += (i ? " " : "") + pws[pid[i]]; else result = "WRONG PASSWORD"; } bool dfs(size_t li, deque<size_t> & pid) { visited[li] = true; for (auto pi : heads[li]) { size_t li1 = li + pws[pi].size(); if (li1 == login.size()) { pid.push_back(pi); return true; } if (!visited[li1] && dfs(li1, pid)) { pid.push_front(pi); return true; } } return false; } }; string passwordCracker(vector<string> pws, string login) { return Cracker(pws, login).result; }
Seems like cookies are disabled on this browser, please enable them to open this website
Password Cracker
You are viewing a single comment's thread. Return to all comments →
C++