Exemplo n.º 1
0
void run_worker(int me, int nprocs) {

   char solution[100];
   uint8_t hash_ptr[HASH_LENGTH + 1];
   int num_workers = nprocs - 1;
   int i;

   // compute work needed by this node
   int domain = strlen(charset);
   int work_per_node = (int)(((float)domain / num_workers) + 0.99);
   int my_start = work_per_node * (me-1);
   int my_end = MIN(domain, my_start + work_per_node);
   //printf("domain: %d, work_per_node: %d\n", domain, work_per_node);
   //printf("%d here: computing <%d, %d>: %d\n", me, my_start, my_end, my_end - my_start);

   // receive hash
   MPI_Recv((void*)hash_ptr, HASH_LENGTH, MPI_UNSIGNED_CHAR, 0, 0, MPI_COMM_WORLD, 0);
   hash_ptr[HASH_LENGTH] = 0;
   //printf("node %d here, hash is ", me);
   //printHash(hash_ptr);

   //while there is work
   for (i = my_start; i < my_end; i++) {
      // compute work and send back results
      crack_password(hash_ptr, solution, i); 
   }
}
Exemplo n.º 2
0
void create_process(unsigned int nb_process, char* file_to_crack, char* dictionary_file){
	params* shared;
	unsigned int i;
	pid_t *pids;
	sem_unlink(SEM_EMPTY);
	sem_unlink(SEM_FULL);
		pids = malloc(sizeof(pid_t)*(nb_process +1));
		if(pids == NULL){
			perror("malloc failed");
			exit(-1);
		}
		shared = create_mem_segment(PARAMS_KEY);
		shared->buf = bounded_buffer_proc_new(BB_KEY);
		shared->dictionary=dictionary_file;
		shared->zipfile = file_to_crack;
		shared->found = false;
		sem_unlink(SEM_EMPTY);
		sem_unlink(SEM_FULL);
		shared->empty = sem_open(SEM_EMPTY,O_CREAT,0666,shared->buf->size);  
		shared->full = sem_open(SEM_FULL,O_CREAT,0666,0);             
		for(i=0; i<nb_process+1; i++){
			pids[i]=fork();
			if(i==(nb_process)){
				if(pids[i]==0){
					fill_buffer(shared);
				}else if(pids[i]<0){
					perror("fork error");
					exit(-1);
				}
			}else{	
				if(pids[i]==0){
					crack_password(shared);
				}else if(pids[i]<0){
					perror("fork error");
					exit(-1);
				}
			}	  
		}
		for(i=0; i<nb_process; i++)
			waitpid(pids[i], NULL, 0);	
		sem_unlink(SEM_EMPTY);
		sem_unlink(SEM_FULL);
		bounded_buffer_proc_free(BB_KEY);
		free_mem_segment(PARAMS_KEY);
}