How is it done to make the billions of combinations possible without loss of time?
I made a random letter generation system (it can do all the combinations), but it loses a lot of time checking results already made by being random, and then I made a system with for
but only up to 2 characters.
This is what I have, as I said, I only managed with 2 digits.
public class Main
{
static boolean terminar = false;
public static void main(String[] args)
{
long init = System.currentTimeMillis();
if(bruteForce(true, true, "0dd", 10, 10000) != "Senha não encontrada")
{
System.out.println("A senha é: " + bruteForce(true, true, "0dd", 10, 10000));
}
else
{
System.out.println("Senha não encontrada");
}
long end = System.currentTimeMillis();
long diff = end - init;
System.out.println("Demorou " + (diff / 1000) + " segundos");
}
public static String bruteForce(boolean numeros, boolean letras, String busca,int maxCaracteres, int limite)
{
String[] todos = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "a", "b", "c", "d", "e", "f", "g"
, "h", "i", "j", "k", "l", "m", "n", "o", "p", "k", "r", "s", "t", "u", "v", "w", "x", "y", "z"
, "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U"
, "V", "W", "X", "Y", "Z", "'", "!", "@", "#", "$", "£", "%", "¢", "¨", "¬", "&", "*", "(", ")", "_", "-"
, "+", "=", "§", "/", ".", "[", "]", "'", "´", "{", "}", "º", "^", "~", "<", ">", ":", ";", "?", "°", "ª",
"|", "¹", "²", "³"};
String combinacao = "";
int quantCaracteres = 2;
double teste = Math.pow(todos.length, 16);
System.out.println(teste);
for(int i = 1; i <= quantCaracteres; i++)
{
for(int h = 0; h <= todos.length -1; h++)
{
for(int j = 0; j <= todos.length -1; j++)
{
combinacao = todos[h] + todos[j];
System.out.println(combinacao);
if(combinacao.equals(busca))
{
return combinacao;
}
combinacao = "";
}
}
//quantCaracteres ++;
}
return "Senha não encontrada";
}
}