Created
November 27, 2025 16:18
-
-
Save salvatorecapolupo/71645a8d2ed8ab501eca1dabaee6d8fa to your computer and use it in GitHub Desktop.
Demo - Ricerca esaustiva - Brute force basico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include <vector> | |
| #include <string> | |
| #include <ctime> | |
| #include <cstdlib> | |
| using namespace std; | |
| int main() { | |
| srand(time(0)); | |
| vector<string> dizionario = { | |
| "acqua", "albero", "ambra", "amico", "angelo", | |
| "barca", "bello", "blu", "buca", | |
| "caffè", "cane", "canto", "casa", "chiave", "cielo", "colle", | |
| "dolce", | |
| "erba", "estate", | |
| "fiore", "fiume", "foresta", | |
| "gatto", "gioco", "goccia", "grano", | |
| "lago", "lampo", "legno", "lente", "luna", | |
| "mare", "mela", "montagna", | |
| "neve", "notte", | |
| "ombra", "onda", "orto", | |
| "pane", "penna", "pesce", "pietra", "pioggia", | |
| "rosso", | |
| "sale", "sasso", "sedia", "sole", "spada", "stella", | |
| "tigre", "torre", | |
| "vento", "verde", "viola", | |
| "zampa", "zattera" | |
| }; | |
| string target = dizionario[ rand() % dizionario.size() ]; | |
| cout << "Dimensione dizionario: " << dizionario.size() << " parole. "<<endl; | |
| cout << "Password target: " << target << endl; | |
| long long tentativi = 0; | |
| // ---- MISURAZIONE DEL TEMPO SENZA CHRONO ---- | |
| clock_t start = clock(); | |
| cout << "Inizio ricerca... " << endl; | |
| for (int i = 0; i < dizionario.size(); i++) { | |
| string parola = dizionario[i]; | |
| tentativi++; | |
| cout << "Proviamo con: "<<parola<<"... " ; | |
| if (parola == target) { | |
| clock_t end = clock(); | |
| double seconds = double(end - start) / CLOCKS_PER_SEC; | |
| cout << "\nTrovato! La tua password era: " << parola << "\n"; | |
| cout << "Num. tentativi: " << tentativi << "\n"; | |
| cout << "Tempo necessario: " << fixed << seconds << " secondi\n"; | |
| return 0; | |
| } | |
| else | |
| cout <<"Non è questa. "<<endl; | |
| } | |
| cout << "Errore: parola non trovata.\n"; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment