mercredi 4 janvier 2023

Random Password with 4 characters from String

I made a code that gives me every possible 4 character combination of a String. Now I need to make a program that chooses 1 random combination as a Password and then goes over every possible combination till it finds the chosen one and then tells me how many guesses it took to find the right one. This is what I have so far:

String alphabet = "ABCabc012!";
        char pw[] = alphabet.toCharArray();
        

        for (int i = 0; i < pw.length ; i++) {
            for (int j = 0; j < pw.length ; j++) {
                for (int k = 0; k < pw.length ; k++) {
                    for (int l = 0; l < pw.length ; l++) {

                        System.out.println(pw[i] + " " + pw[j] + " " + pw[k] + " " + pw[l]);
                    }
                }
            }
        }

I tried to store the pw[] in an array but I dont know exactly how to do it.




Aucun commentaire:

Enregistrer un commentaire