Advertisement
Transformator

Untitled

Dec 16th, 2014
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include "include/CkZip.h"
  5. #include <time.h>
  6.  
  7. using namespace std;
  8.      
  9. string createWord(char letters[], int ziffern[])
  10. {
  11.   string word = "";
  12.            
  13.   for(int i=0; i<sizeof(ziffern); i++) { word += letters[ziffern[i]]; }
  14.     return word;
  15. }
  16.      
  17. bool testWord(string word)
  18. {
  19.     CkZip zip;
  20.     zip.UnlockComponent("Du hast es geschaft!.txt");
  21.     zip.SetPassword(word.c_str());
  22.     bool success = zip.OpenZip("Brut.zip");
  23.   if(!success)
  24.   {
  25.     cout << "TRY FOR '" << word << "' - FALSE" << endl;
  26.     return false;
  27.   } else {
  28.     cout << "TRY FOR '" << word << "' - TRUE" << endl;
  29.         int numFilesUnzipped = zip.Unzip("extract");
  30.         if(numFilesUnzipped < 0)
  31.         {
  32.             cout << "PACK OUT ERROR" << endl;
  33.         }
  34.     return true;
  35.   }
  36. }
  37.  
  38. double getTime() {
  39.   struct tm y2k;
  40.   double seconds;
  41.     time_t timer;
  42.  
  43.   y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
  44.   y2k.tm_year = 100; y2k.tm_mon = 0; y2k.tm_mday = 1;
  45.  
  46.   time(&timer);
  47.  
  48.   seconds = difftime(timer,mktime(&y2k));
  49.     return seconds;
  50. }
  51.      
  52. int main()
  53. {
  54.   /* --- informationen ---
  55.   * ziffern: 6
  56.   * buchstaben: abcdprsuw1234
  57.   */
  58.            
  59.   // --- parameter ---
  60.   char letters[] = "abcdprsuw1234";
  61.   int length = 6;
  62.            
  63.   // --- ausrechnen ---
  64.   int ziffern[length];
  65.   for(int i=0; i<length; i++) { ziffern[i] = 0; }
  66.            
  67.   int times = 1;
  68.   for(int i=0; i<length; i++) { times *= (sizeof(letters) / sizeof(letters[0])); }
  69.            
  70.   // --- vordefinitionen ---
  71.   string word;
  72.   bool stop = false;
  73.     double time1 = getTime();
  74.            
  75.   for(int i=0; i<times; i++)
  76.   {
  77.     if(stop == false)
  78.     {
  79.       word = createWord(letters, ziffern);
  80.       if(testWord(word)) { stop = true; }
  81.       else
  82.       {
  83.                 ziffern[length-1]++;
  84.                                            
  85.                 for(int i=length; i>0; i--)
  86.         {
  87.             if(ziffern[i] == length-1)
  88.           {
  89.             ziffern[i] = 0;
  90.                         ziffern[i-1]++;
  91.           }
  92.         }
  93.         if(ziffern[0] == length-1)
  94.         {
  95.             cout << "ERROR: NO PASSWORD FOUND" << endl;
  96.             stop = true;
  97.         }
  98.       }
  99.     } else {
  100.             double time2 = getTime();
  101.             cout << "Zeit:" << time2 - time1 << endl;
  102.         }
  103.   }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement