I came here to ask if there is a way to prevent already guessed guesses from being guessed again in my brute-force java program. Basically I used a "rand.nextInt" in my program but the program will guess already guessed passwords again even if they were incorrect. How could I prevent this as it wastes time and processing power to guess already guessed numbers.The code is below:
import java.util.*;
import java.io.*;
class pwcracker
{
public static void main (String[] args)
{
Scanner scan = new Scanner( System.in );
Random rand = new Random();
String pw, choices, guess;
long tries;
int j, length;
System.out.println("Enter a password that is up to 5 chars and contains no numbers: ");
pw = "" + scan.nextLine();
length = pw.length();
choices = "abcdefghijklmnopqrstuvwxyz";
tries = 0;
guess = "";
System.out.println("Your pw is: " + pw);
System.out.println("The length of your pw is: " + length);
System.out.println("for TEST- Guess: " + guess + "pw :"+pw);
if (!guess.equals(pw)){
while (!guess.equals(pw))
{
j = 0;
guess = "";
while ( j < length )
{
guess = guess + choices.charAt( rand.nextInt( choices.length() ) );
j = j + 1;
if (guess .equals(pw))
{
System.out.println("Match found, ending loop..");
break;
}
}
System.out.println("Guess: " + guess + " pw :"+pw);
tries = tries + 1;
}
}
System.out.println("Here is your password: " + guess);
System.out.println("It took " + tries + " tries to guess it.");
}
}
Aucun commentaire:
Enregistrer un commentaire