计算特定的字符集的所有组合,蛮力匹配?组合、字符集

2023-09-11 23:21:04 作者:述妄

在练多线程,我想简单地构建,可以计算出一个字符集的所有可能组合的应用程序(即蛮力开裂/匹配)和分发工作线程中,要真正去衡量和亲眼目睹如何线程可以影响在不同的系统算法的时间。

In practising multithreading, I had wished to simply build an application that could calculate all possible combinations of a character set (i.e. brute force cracking/matching) and distributing work among threads, to really get to measure and see first hand how the threading can affect the algorithm's time on different systems.

该算法计算这个,取得了很大的挑战,我至今。在最近的一个线程(What将是一个有效的方式来增加多线程这个简单的算法?)我似乎趴下什么,我需要做的(容易地通过每一个字符范围内的特定部分分配工作)虽然算法根本不工作,我不明白的复杂性足以解决它在我的应用程序。

The algorithm to calculate this, has been a great challenge to me so far. On a recent thread (What would be an efficient way to add multithreading to this simple algorithm?) I seemed to get down what I needed to do (easily pass specific parts of each character range to distribute work) although the algorithm simply did not work, and I did not understand the complexity enough to fix it in my application.

在一个简单的,迭代的方式,我怎么能计算给定的字符集的每个组合,与特定的长度(即5长?)

In a simple, iterative manner, how could I compute every combination of a given character set, with a specific length (i.e. 5 in length?)

例如:

unsigned char range[] = "abcdefghijklmnopqrstuvwxyz0123456789";
brute_force(range, len); //character set, length of string to compute all combinations of
//...

我将非常感激,以减轻一些压力在寻找这样做的正确的概念。

I would be very thankful to relieve some stress on finding the proper concepts of doing this.

推荐答案

办法一:

One approach:

void brute_force(String range, int len) {
        for (int i = 0; i < range.length(); ++i) {
           final String x  = "" + range.charAt(i);
           Thread t = new Thread(){
               public void run() { brute_force(x, range[].replace(x, ""), len); };
            };
            t.start();
        }
}

其中, brute_force(字符串,字符串,INT)将产生的组合。