Till Gades 10 mesi fa
commit
96a26c2834
2 ha cambiato i file con 103 aggiunte e 0 eliminazioni
  1. 2 0
      README.md
  2. 101 0
      main.cpp

+ 2 - 0
README.md

@@ -0,0 +1,2 @@
+# Projekt Passwort Checker
+

+ 101 - 0
main.cpp

@@ -0,0 +1,101 @@
+#include <iostream>
+#include <string>
+#include <fstream>
+#include <chrono> // fuer die Zeitmessung
+#include <stdint.h>
+
+using namespace std;
+
+const char first_char = '!';
+const char last_char = '~';
+
+char get_new_char(char prev_char) {
+  if (prev_char == 0) {
+    return first_char;
+  } else if (prev_char < last_char) {
+    return prev_char + 1;
+  }
+  return first_char;
+}
+
+int bruteforce(string passwd) {
+  char list[200] = {'!',0};
+  uint64_t counter = 0;
+  int pos = 0;
+
+  while (passwd.compare(list)) {
+    if (list[pos] == last_char) {
+      while (list[pos] == last_char) {
+        list[pos] = get_new_char(list[pos]);
+        pos += 1;
+        list[pos] = get_new_char(list[pos]);
+      }
+      pos = 0;
+    } else {
+      list[pos] = get_new_char(list[pos]);
+    }
+    counter += 1;
+  }
+  cout << "Das Passwort lautet: " << list << endl;
+  cout << "Es wurden " << counter << " Versuche benoetigt" << endl;
+  return 1;
+}
+
+// Funktion zum überprüfen des Passwortes mit dem Dictionary
+int compare_passwd(string passwd, string dict_file) {
+  // fstream zum Oeffnen der Datei
+  fstream dict(dict_file, ios::in);
+  // char zum einlesen einer Zeile max 200 Zeichen
+  char list[200] = {0};
+  // Statusvariable zum Erkennen, ob das Passwort gefunden wurde
+  // Standard nein
+  int a = 0;
+  if(!dict.is_open()) {
+    cout << "Dictionary konnte nicht geoeffnet werden!" << endl;
+    return 0;
+  }
+// Schleife, um alle Passworter zu ueberpruefen, oder bei gefundenem Passwort abbrechen
+  while (dict.getline(list, 200)) {
+    // Passwort vergleichen
+    if (passwd.compare(list) == 0) {
+      a = 1;
+      // Wenn das Passwort gefunden wurde muss nicht weiter ueberprueft werden
+      dict.close();
+      break;
+    }
+  }
+  // Datei wieder schliessen
+  dict.close();
+  // Rueckgabe, ob das Kennwort gefunden (1) wurde oder nicht (0)
+  return a;
+}
+
+int main() {
+
+  string passwd;
+  // Name der Datei
+  string dict = "passdict.txt";
+
+  cout << " ***** Passwortueberpruefung ***** " << endl;
+  cout << endl;
+  cout << "Bitte ein Passwort eingeben, das ueberprueft werden soll." << endl;
+  cout << "Passwort: ";
+  cin >> passwd;
+
+  // Ueberpruefung, ob das Password bekannt ist.
+//  if (compare_passwd(passwd, dict)) {
+//    cout << "Passwort gefunden" << endl;
+//  } else {
+    cout << "Passwort nicht gefunden" << endl;
+    cout << "Beginne Bruteforce" << endl;
+    auto start = chrono::high_resolution_clock::now();
+    if (bruteforce(passwd)) {
+      cout << "Passwort gefunden" << endl;
+    }
+    auto end = chrono::high_resolution_clock::now();
+    chrono::duration<double, std::milli> duration = end - start;
+    cout << "Das finden hat " << duration.count() << " Millisekunden gedauert." << endl;
+//  }
+
+  return 0;
+}