Ask your own question, for FREE!
Computer Science 9 Online
mhchen:

My thoughts on creating a dictionary attack because googling them either comes up with way too complicated algorithms, or news articles trying to explain ethics of them -__-

mhchen:

Assuming the character set is only lower case alphabet numbers. For 1 letter, there's 26 permutations. Then for 2 letters there is 26^2 permutations. Then for n letters there is 26^n permutations. I guess the runtime is O(26^n)? lol

mhchen:

```javascript let chars = ; let n = 1; while(n<10){ /* How would I print out all permutations from 1 letter to 10 letters here?*/ } ``` Obviously for n = 1 I would have 1 for loop for n=2 I could use 2 for loops but that would create a problem where I'd need more and more for-loops...I think

mhchen:

``` let chars = ["a"..."z"]; let n = 1; while(n<10){ //print out first 10 permutations let i = n; //decrement this value so we have i-loops while(i>0){ for(let j=0;j<chars.length;j++){ //iterate through chars console.log(chars[j]); } i--; } n++; } ``` I'm not quite there yet...

mhchen:

I'd like someone to help come up with a permutation algorithm for me

mhchen:

I found this code online: ```javascript function getAllPermutations(string) { var results = []; if (string.length === 1) { results.push(string); return results; } for (var i = 0; i < string.length ; i++) { var firstChar = string; var charsLeft = string.substring(0, i) + string.substring(i + 1); var innerPermutations = getAllPermutations(charsLeft); for (var j = 0; j < innerPermutations.length ; j++) { results.push(firstChar + innerPermutations[j]); } } return results; } ``` but the problem is, there's 26 possible elements for the first position, not ... you know, the length of the string.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!