import java.util.ArrayList;
class Main {
static String passwd = "f";
public static void main(String[] args) {
boolean passwdNotGuessed = true;
String curAttempt = "a";
long tries = 0;
while (passwdNotGuessed) {
tries++;
if (login(curAttempt)) {
passwdNotGuessed = false;
System.out.println("Password: " + curAttempt);
System.out.println("Tries: " + tries);
}
curAttempt = getSuccesor(curAttempt);
}
}
public static String getSuccesor(String oldString) {
//Make a character array
ArrayList<Character> letters = new ArrayList<Character>();
for (char c : oldString.toCharArray()) {
letters.add(c);
}
int asciiValue = (int)(letters.get(letters.size()-1));
if (asciiValue == 122) {
//Check if all letters are z.
boolean allLettersZ = true;
for (int x = 0; x < letters.size(); x++) {
if (letters.get(x) != 'z') {
allLettersZ = false;
break;
}
}
if (allLettersZ) {
int length = letters.size();
letters.clear();
for (int i = 0; i <= length; i++) {
letters.add((char)(97));
}
}else{
//Go back to letter a;
}
}else{
newAsciiValue = asciiValue+1;
}
//return newString;
}
public static boolean login(String password) {
return password.equals(passwd);
}
}