Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <stdlib.h>
- #include <string.h>
- #include <Windows.h>
- #include <process.h>
- char alfabet[] = "abcd";
- char bufor[100];
- int n = 4;
- int L = strlen(alfabet);
- bool czywbuf = false;
- bool odgadnieto = false;
- bool kendprac = false;
- char haslouzytk[100] = "acba";
- void haslogen(int n, int L, int level, char * alfabet, char * bufor)
- {
- if (level == n)
- {
- bufor[level] = 0;
- czywbuf = true;
- printf("%s\n", bufor);
- while (czywbuf == true) {}
- if (odgadnieto == true) { _endthread(); }
- }
- else {
- for (int i = 0; i<L; i++)
- {
- bufor[level] = alfabet[i]; haslogen(n, L, level + 1, alfabet, bufor);
- }
- }
- }
- void generuj_haslo(void * Args)
- {
- haslogen(n, L, 0, alfabet, bufor);
- kendprac = true; _endthread();
- }
- void sprawdz_poprawnosc_hasla(void * Args)
- {
- while (odgadnieto == false && kendprac == false)
- {
- if (czywbuf == true)
- {
- if (strcmp(haslouzytk, bufor) == 0)
- {
- printf("Znaleziono haslo\n");
- czywbuf = false;
- odgadnieto = true;
- }
- else { czywbuf = false; }
- }
- }
- if (kendprac == true)
- {
- printf("Nie odnaleziono hasla\n");
- } _endthread();
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- HANDLE producent = (HANDLE)_beginthread(generuj_haslo, 0, NULL);
- HANDLE konsument = (HANDLE)_beginthread(sprawdz_poprawnosc_hasla, 0, NULL);
- WaitForSingleObject(producent, INFINITE);
- WaitForSingleObject(konsument, INFINITE);
- system("pause");
- return 0;
- }
Add Comment
Please, Sign In to add comment