コード例 #1
0
// Função usada pela thread produtora
void *producePasswords(void *v) {

  char pass[10];
  int i;

  for (i = 0; i < PASS_SIZE; i++) {
    pass[i] = 'a';
  }
  pass[i] = '\0';

  // Loop que roda enquanto for possivel gerar novas senhas
  do {

    // Se alguma consumidora já encontrou a senha desejada, não produz mais senhas
    if (found) {
      return NULL;
    }

    // Bloqueia o semáforo que regula o acesso à fila de senhas geradas
    sem_wait(&sem);

    //printf("insere %s\n", pass);
    filaPasswords = insertFila(filaPasswords, pass);

    // Libera o semáforo das filas
    sem_post(&sem);
    usleep(1);
  } while (getNextPassword(pass));


  no_more_pass = 1;


  return NULL;
}
コード例 #2
0
ファイル: SakiDay11.cpp プロジェクト: masakotoda/SakiPublic
void SakiDay11::compute2()
{
	std::string password = "******";
	while (true)
	{
		getNextPassword(password);
		if (isGoodPassword(password))
		{
			break; // next one
		}
	}

	while (true)
	{
		getNextPassword(password);
		if (isGoodPassword(password))
		{
			break; // next to next one
		}
	}

	std::cout << password << std::endl;
}
コード例 #3
0
ファイル: cracker.c プロジェクト: mmhoust/school
void getNextPassword(char* password, int depth, int n){
	if(depth == 0){
		return;
	}
	// if end of range i.e 0-9 jump to next range
	if(password[depth-1] == '9'){
		password[depth-1] = 'A';
		return;
	}else if(password[depth-1] == 'Z'){
		password[depth-1] = 'a';
		return;
	}else if(password[depth-1] == 'z'){
		// get when one letter has iterated through ah nevermind idk how to explain what
		// i did it works though
		getNextPassword(password,depth-1,n);
		for(int i = depth -1; i<n; ++i){
			password[i] = '0';
		}
		return;
	}else {
		password[depth-1] += 1;
		return;
	}
}