Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <stdio.h>
- #include "include/CkZip.h"
- #include <time.h>
- using namespace std;
- string createWord(char letters[], int ziffern[])
- {
- string word = "";
- for(int i=0; i<sizeof(ziffern); i++) { word += letters[ziffern[i]]; }
- return word;
- }
- bool testWord(string word)
- {
- CkZip zip;
- zip.UnlockComponent("Du hast es geschaft!.txt");
- zip.SetPassword(word.c_str());
- bool success = zip.OpenZip("Brut.zip");
- if(!success)
- {
- cout << "TRY FOR '" << word << "' - FALSE" << endl;
- return false;
- } else {
- cout << "TRY FOR '" << word << "' - TRUE" << endl;
- int numFilesUnzipped = zip.Unzip("extract");
- if(numFilesUnzipped < 0)
- {
- cout << "PACK OUT ERROR" << endl;
- }
- return true;
- }
- }
- double getTime() {
- struct tm y2k;
- double seconds;
- time_t timer;
- y2k.tm_hour = 0; y2k.tm_min = 0; y2k.tm_sec = 0;
- y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
- time(&timer);
- seconds = difftime(timer,mktime(&y2k));
- return seconds;
- }
- int main()
- {
- /* --- informationen ---
- * ziffern: 6
- * buchstaben: abcdprsuw1234
- */
- // --- parameter ---
- char letters[] = "abcdprsuw1234";
- int length = 6;
- // --- ausrechnen ---
- int ziffern[length];
- for(int i=0; i<length; i++) { ziffern[i] = 0; }
- int times = 1;
- for(int i=0; i<length; i++) { times *= (sizeof(letters) / sizeof(letters[0])); }
- // --- vordefinitionen ---
- string word;
- bool stop = false;
- double time1 = getTime();
- for(int i=0; i<times; i++)
- {
- if(stop == false)
- {
- word = createWord(letters, ziffern);
- if(testWord(word)) { stop = true; }
- else
- {
- ziffern[length-1]++;
- for(int i=length; i>0; i--)
- {
- if(ziffern[i] == length-1)
- {
- ziffern[i] = 0;
- ziffern[i-1]++;
- }
- }
- if(ziffern[0] == length-1)
- {
- cout << "ERROR: NO PASSWORD FOUND" << endl;
- stop = true;
- }
- }
- } else {
- double time2 = getTime();
- cout << "Zeit:" << time2 - time1 << endl;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement