Parallelization of brute force search algorithm with threads in C ++

I am working on a brute force program in C ++, which so far only deals with alpha-numeric values ​​(lowercase only) and with an unknown length password.

I work with a quad-core processor, so I split the list of features into four sections and one thread works on each of them.

Sections:

000...0 to 8zz...z 900...0 to hzz...z i00...0 to qzz...z r00...0 to zzz...z 

Can I better use streams to increase speed? Since only 1 in 4 threads will ever reach the password, it seems that 3/4 of the program is a waste of time.

It would seem that if I could combine the threads, it would be more efficient, but I can not imagine how to do it.

Any advice is much appreciated, I'm new to streaming.

* EDIT: I must clarify that, since this is a fairly simple program for academic purposes, I actually only crack one password and give a signal to kill the remaining three threads as soon as it finds them. *

+4
source share
4 answers

Here are some ideas:

  • You can use the atomic boolean to communicate over the streams that were found in the password. Each thread simply needs to periodically check (for example, before trying the next password) if the flag is set.
  • Instead of statically dividing the work into four equal parts, you can also use one central list of passwords to try to allow each element to capture the thread as needed.
+4
source

for 4 threads it is most efficient. There is no lead time, because with brute force you have to check all the possibilities ...

+1
source

You can create one global bool variable that will be true if some of the threads found the correct password (you set it to true if you found the password) and check if it is set to true, for example, by trying every 1000 passwords in each thread. This will reduce this inefficient iteration in threads when another thread has already found the correct password.

* at startup, you must set this global variable to false .

0
source

You can set up a zero-initialized semaphore and a killer thread waiting for this semaphore. When the thread finds the answer, let it bounce the semaphore, untying the killer thread so that it can send other threads to the thread.

The same as when checking the global flag, only the global thread is checked in the kernel, and not at each iteration, but only on context switches.

0
source

All Articles