The purpose of this code is to find a password with brute force cracking where as it will try all the possible combinations until it finds the correct password. For example, it will start like a then b then c . . . ab . . . cz . . . dd and so on until it finds the correct password. All of it works, but the performance is rather slow after it runs for like 20 seconds; it starts to become choppy. I am looking for how to improve the performance of this so it will remain running constantly at 40 fps+.
I feel like when I run this code it must create memory leaks and lag. I'm just goofing off to learn a little and use my free time, but I would prefer if this ran more smooth. I am not sure how to detect memory leaks well, but if someone can point mine out I should be able to understand it better.
This isn't anything to be used for illegal use, it is just for pure fun.
//Brute Hack js
var wholeList = [];
var runBrute = null;
var charList = null;
var minChar = null;
var maxChar = null;
var answer = 0;
var a=0;
var b=0;
var c=0;
var d=0;
var e=0;
var f=-1;
var possibilities = 0;
var possAns = [];
var ans = null;
function bruteHack(startingChar,minCha,maxCha, endingChar) {
minChar = minCha;
maxChar = maxCha;
x = 0;
for(var i = 33; i<125;i++) {
currentCharCode = String.fromCharCode (i);
//Compiles wholeList
wholeList[x] = currentCharCode;
x++;
//Find num val of starting and end char
if(currentCharCode.search(startingChar) > -1 ) {
startingChar = i;
//alert("starting:"+startingChar);
}
if(currentCharCode.search(endingChar) > -1) {
endingChar = i;
//alert("Ending:"+endingChar);
}
}
//33 to 125 charCode
if(startingChar != null && endingChar != null) {
charToSearchFor = (endingChar - startingChar); // How many chars to find between the two points
charList = []; //Storing my list
//Compile my array of vars
x = startingChar;
for(var i = 0;i<=charToSearchFor;i++) {
currentCharCode = String.fromCharCode (x);
charList[i] = currentCharCode;
x++;
}
runBrute = intervalTrigger(); //Invokes our solver interval
}
return wholeList;
}
function intervalTrigger() {
return window.setInterval(bruteHackSolve,0025);
}
function bruteHackSolve() {
//Creates a random answer
if( answer != 1 ) {
//Init vars
for(i=0;i<maxChar;i++) {
possAns[i] = 0;
}
for(i=0;i<minChar;i++) {
possAns[maxChar-i] = charList[0];
}
for(i=minChar;i<=maxChar;i++) {
possibilities+= Math.pow(charList.length,i); //Amount of possible entry codes
}
//End of init vars
for (i=0; i< maxChar;i++) {
if(i == 0) {
ans = wholeList[Math.floor(Math.random() * wholeList.length)];
}
else {
ans = ans.concat(wholeList[Math.floor(Math.random() * wholeList.length)]);
}
}
answer = 1; //Turns off random answer gen
}
//alert(ans);
if (ans != null) {
//Start the process to find the passcode
//alert(possAns.join(""));
f++;
possAns[maxChar] = charList[f];
if(f==charList.length) {
f=0;
e++;
possAns[maxChar-1] = charList[e];
}
else if(e==charList.length) {
e=0;
d++;
possAns[maxChar-2] = charList[d];
}
else if(d==charList.length) {
d=0;
c++;
possAns[maxChar-3] = charList[c];
}
else if(c==charList.length) {
c=0;
b++;
possAns[maxChar-4] = charList[b];
}
else if(b==charList.length) {
b=0;
a++;
possAns[maxChar-5] = charList[a];
}
tempStore = possAns.join("");
document.getElementById('outputDisplay').innerHTML = "<p>"+tempStore.replace(0,"")+"</p>";
if(tempStore.replace(0,"") == ans) {
window.clearInterval(runBrute);
document.getElementById('outputDisplay').innerHTML = "<p>"+ans+"</p>";
alert("Match has been found!");
}
}
}