I'm currently working on a brute-force password cracking method because I want to try it out and do something new. I'm providing the methods I'm working on below but here's first what I'm trying to do. Initially, I'm generating the hash of a possible value for the password and comparing it against the one I have in my "sample.txt" file that contains a list of hashed passwords. So basically my goal is to read the hashed password value from that external file and compare it against all possible 3/4 hashed password values.
When I ran the program, I accidentally kept the condition of the while statement in the "BruteForce" method to true and it endlessly ran, however when I set the condition to keeping the password value generated to be having a length of 3 and 4 only, the program suddenly terminates I don't know why, I've tried debugging the program to see where things go wrong but i was not able to deduce anything.
Here's what's in my main method and the "bruteforce" method :
public static void bruteForce(String username, String hashed_pw) {
//username is the username from the input
//hashed_pw is the hashed value of password
String chars = "0123456789abcdefghijklmnopqrstuvwxyz";
char[] charset = chars.toCharArray();
TestClass bf = new TestClass(charset, 1); //random generation of possible pw value
String attempt = bf.toString();
while ((attempt.length() == 3) && (attempt.length() == 4)) {
String hashed_input = doHash(attempt); //hash the possible pw value
System.out.println("");
System.out.println("Attempt result is: " + attempt);
System.out.println("Hashed of attempt: " + hashed_input);
System.out.println("Hashed Password is : " + hashed_pw);
System.out.println("");
if (hashed_input.equals(hashed_pw)) {
System.out.println("Password Found: " + attempt);
System.out.println(username + "'s password is: " + attempt);
break;
} else {
attempt = bf.toString();
bf.increment();
}
// attempt = bf.toString();
// System.out.println("" + attempt);
// bf.increment();
// return attempt;
}
// return attempt;
}
public char[] cs;
public char[] cg;
public void increment() {
int index = cg.length - 1;
while (index >= 0) {
if (cg[index] == cs[cs.length - 1]) {
if (index == 0) {
cg = new char[cg.length + 1];
Arrays.fill(cg, cs[0]);
break;
} else {
cg[index] = cs[0];
index--;
}
} else {
cg[index] = cs[Arrays.binarySearch(cs, cg[index]) + 1];
break;
}
}
}
Aucun commentaire:
Enregistrer un commentaire