c - Multi-threaded bruteforce algorithm -
i have multi-threaded programme bruteforces password incrementing string, taking chars delimited string.
i thought piece "dictionnary" (set of chars) between threads i'm wrong.
what i'm doing splitting dictionnary many pieces there threads, , allow them work on subset of chars.
here dictionnary :
static const char tab[] = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" "0123456789" "!*~";
so i'm doing stupid, since if split between 4 threads, 1 able test i.e. "adef" never "a*1b".
so guess there's much improve solution, can't wrap head around it.
here incrementing algorithm (there's more it, i'm putting what's important):
void *func(void * bound){ char test[5]="0000"; int u = bound + nb_pas; (int h = bound; h <= u; ++h){ test[3] = tab[h]; (int k = bound; k <= u; ++k){ test[2] = tab[k]; (int j = bound; j <= u; ++j){ test[1] = tab[j]; (int = bound; <= u; ++i){ test[0] = tab[i]; if(finished == 1){ for(int r = 1 ; r < nb_thread; r++ ){ pthread_cancel(tid[r]); } homecoming exit_success; } char *hash = crypt_r(test,salt,cdata); if(strcmp(hash,ciphertext) == 0 ){ // impression du résultat printf("password found: %s\n", test); printf("hashed version of password %s\n", hash); printf("it took %f seconds finish in %i steps \n", elapsed, compteur); finished = 1; homecoming exit_success; } } } } } if (finished == 0){ printf(" no match\n"); } homecoming 0; }
where bound
int
passed thread corresponding (# of chars / # of threads) * thread index
, nb_pas
(# of chars / # of threads)
how should approach ? thought simulating incrementing loops before assigning function threads, i'm not sure how it...
thanks help
edit
here how spawn threads
for(int = 0; < nb_thread; i++){ int b = nb_pas*i; if (pthread_create(&tid[i],null,func, b)!=0){ printf("une erreur s'est produite"); homecoming exit_failure; } }
you may seek like
for (i=0; i<nbthread; i++) { pthread_create(......,func,i*strlen(tab)/nbthread); }
then :
func(void *bound) { int start = (int)bound; int end = start+strlen(tab)/nbthread; (i=start; i<end];i++) { // 1 piece of alphabet test[0] = tab[i]; for(j=0; j<strlen(tab); j++) { // every letter test[1] = tab[j]; .... }
c multithreading algorithm brute-force
No comments:
Post a Comment