Given a dictionary based simple password, create all possible (special character) passwords based on a provided mapping. Input: face Map: {a -> @, 4, A} Output: f@ce, f4ce, fAce
Anónimo
here's a javascript version using recursion: var mapPassword = (function () { var map = { a: ['A', '@', '4'], e: ['E', '#'] }; return function recur (pw) { //base case if (pw.length === 1) return map[pw] || pw; //otherwise var current = map[pw.charAt(0)], rest = recur(pw.slice(1)), //recursively get possible combinations for substring result = [], i, j, k, l; if (current) { // has map for (i = 0, j = current.length; i < j; i++) { for (k = 0, l = rest.length; k < l; k++) { result.push(current[i] + rest[k]); } } } else { // no map for (k = 0, l = rest.length; k < l; k++) { result.push(pw.charAt(0) + rest[k]); } } return result; } })();