title: Brute force password cracker Java
body: <p>I am doing an assignment for class which I have to create a brute force password cracker in java.</p>
  
  <ol>
  <li>Write a function using Recursion to crack a password.  The password is of unknown length (maximum 10) and is made up of capital letters and digits.  (Store the actual password in your program, just for checking whether the string currently obtained is the right password.)</li>
  </ol>
  
  <p>The solution I have is:</p>
  
  <pre><code>import java.util.Arrays;
  
  public class BruteForce {
    public static void main(String[] args) {
      bruteForce(3);
    }
  
    public static String bruteForce(int size) {
      int[] password = new int[size];
      String[] finalPassword = new String[size];
      for (int i = 0; i &lt; size; i++) {
        password[i] = 0;
        finalPassword[i] = "";
      }
      String pass = "AAA";
      return computePermutations(size, password, 0, pass);
    }
  
    private static String computePermutations(int size, int[] password, int position, String pass) {
      String testString = "";
      String assemble = "";
      for (int i = 0; i &lt; 36; i++) {
        password[position] = i;
  
        if (position != size - 1) {
          testString = computePermutations(size, password, position + 1, pass);
          if (testString != "") {
            return testString;
          }
        } else if (position == size - 1) {
          for (int j = 0; j &lt; size; j++) {
  
            switch (password[j] + 1) {
              case 1:
                assemble = assemble + "A";
                break;
              case 2:
                assemble = assemble + "B";
                break;
              case 3:
                assemble = assemble + "C";
                break;
              case 4:
                assemble = assemble + "D";
                break;
              case 5:
                assemble = assemble + "E";
                break;
              case 6:
                assemble = assemble + "F";
                break;
              case 7:
                assemble = assemble + "G";
                break;
              case 8:
                assemble = assemble + "H";
                break;
              case 9:
                assemble = assemble + "I";
                break;
              case 10:
                assemble = assemble + "J";
                break;
              case 11:
                assemble = assemble + "K";
                break;
              case 12:
                assemble = assemble + "L";
                break;
              case 13:
                assemble = assemble + "M";
                break;
              case 14:
                assemble = assemble + "N";
                break;
              case 15:
                assemble = assemble + "O";
                break;
              case 16:
                assemble = assemble + "P";
                break;
              case 17:
                assemble = assemble + "Q";
                break;
              case 18:
                assemble = assemble + "R";
                break;
              case 19:
                assemble = assemble + "S";
                break;
              case 20:
                assemble = assemble + "T";
                break;
              case 21:
                assemble = assemble + "U";
                break;
              case 22:
                assemble = assemble + "V";
                break;
              case 23:
                assemble = assemble + "W";
                break;
              case 24:
                assemble = assemble + "X";
                break;
              case 25:
                assemble = assemble + "Y";
                break;
              case 26:
                assemble = assemble + "Z";
                break;
              case 27:
                assemble = assemble + "0";
                break;
              case 28:
                assemble = assemble + "1";
                break;
              case 29:
                assemble = assemble + "2";
                break;
              case 30:
                assemble = assemble + "3";
                break;
              case 31:
                assemble = assemble + "4";
                break;
              case 32:
                assemble = assemble + "5";
                break;
              case 33:
                assemble = assemble + "6";
                break;
              case 34:
                assemble = assemble + "7";
                break;
              case 35:
                assemble = assemble + "8";
                break;
              case 36:
                assemble = assemble + "9";
                break;
            }
  
          }
          System.out.println(assemble);
          if (assemble.equalsIgnoreCase(pass)) {
            System.out.println("Password is: " + assemble);
            break; //replace this with: return assemble;
          } else {
            assemble = "";
          }
        }
  
  
      }
      return "";
    }
  }
  </code></pre>
  
  <p>However, when I run the program, the password AAA never seems to work but 998 works just fine, what exactly is wrong?</p>