-2

I am trying to write a kind of brute force script in javascript! This is what I have so far:

var charset = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j,", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];

function bruteForce() {

    var password = document.getElementById("enteredPassword").value;
    var crackedPassword = "";

    while (true) {
        if (crackedPassword != password) {
            for (int i; i < charset.lenght; i++) {
                crackedPassword += charset[i];
                document.getElementById("currentPassword").value = crackedPassword;
            }
        } else {

            document.getElementById("currentPassword").value = crackedPassword;
            alert("finished");
        }
    }
}

It gives me the following error: Uncaught SyntaxError: Unexpected identifier
the line causing the problem: for(int i = 0; i < charset.lenght; i++){


And: Uncaught ReferenceError: bruteForce is not defined
line: <input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" />

I thing it has to do with that crackedPassword += charset[i];
But what I saw here, confused me, because there has to be another cause!

5
  • looks like a typo: charset.length not charset.lenght ? Commented Oct 23, 2015 at 15:56
  • There is an extra bracket Commented Oct 23, 2015 at 15:57
  • Thanks, but I'm still getting that error on the same line Commented Oct 23, 2015 at 15:58
  • This won't work by the way. The crackedPassword will contain abcdefghijklmnopqrstuvwxyzabcdefghijk..... Commented Oct 23, 2015 at 16:00
  • Of course...comming from java you know I'm sorry thank you :) Commented Oct 23, 2015 at 16:00

2 Answers 2

2

for(int i = 0; i < charset.lenght; i++){

should be for(var i = 0; i < charset.length; i++){

Also inline event handlers like <input onClick = "bruteForce()" name="input" type="image" src="arrow.jpg" align="right" /> expect the handler to be in global scope.

So if the code you shared is enclosed in some other wrapper function, it probably won't work. Otherwise it's the first syntax error causing the second as well...

Sign up to request clarification or add additional context in comments.

Comments

0

Length is spelt wrong in your for loop. It should be length not lenght.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.