作为一个小项目,我正在制作一个“密码”破解程序,它只是暴力破解字母表,数字和符号的所有排列,直到密码被猜到。
当然,这是非常低效的,我正在寻找使它更快一点的方法。
我的想法是让排列按照它们的大小顺序发生。所以现在,它将从中的第一个字符开始,并不断添加下一个字符,猜测变得越来越大,越来越大。例如..ArrayList
具有值的 A,我当前的程序将创建如下排列:ArrayList(A, B, C, D)
(A), , , , ,(A, B)(A, B, C)(A, B, C, D)(A, B, D)(A, B, D, C)
但是一种更有效的方法(因为大多数密码的长度不是60多个字符),那就是像这样进行排列
(A)、、、、、、、等(B)(C)(D)(A, B)(A, C)(A, D)(B, A)(B, C)
这是我当前的程序的样子:
import java.util.ArrayList;
import java.util.Arrays;
public class BruteForce
{
public static String password = "rand1";
public static void main(String[] args) {
ArrayList<Character> characters = new ArrayList<>(Arrays.asList('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', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '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', '_', '-', '!', '$'));
initialPermutations(characters);
}
public static void initialPermutations(ArrayList<Character> characters) {
ArrayList<Character> sub = new ArrayList<>();
finalPermutations(sub, characters);
}
public static void finalPermutations(ArrayList<Character> sub, ArrayList<Character> a) {
int L = a.size();
char[] cs = new char[sub.size()];
for(int i = 0; i < cs.length; i++) {
cs[i] = sub.get(i);
}
String output = new String(cs);
if(output.equals(password)) {
System.out.println("The password is " + output);
System.exit(-1);
}
if (L == 0) {
System.out.println(output);
}
}
}
}
关于如何将其改进为更“有效”(实际上不是更有效,只是对于更短的密码更有用)方法的任何想法?
临摹微笑
缥缈止盈
相关分类