Advertisement
Transformator

cplusplus001

Dec 12th, 2014
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <stdio.h>
  4. #include "chilkat/lib/libchilkat-9.5.0.a"
  5.  
  6. using namespace std;
  7.      
  8. string createWord(char letters[], int ziffern[])
  9. {
  10.   string word = "";
  11.            
  12.   for(int i=0; i<sizeof(ziffern); i++) { word += letters[ziffern[i]]; }
  13.     return word;
  14. }
  15.      
  16. bool testWord(string word)
  17. {
  18.     CkZip zip2;
  19.     zip2.UnlockComponent("Du hast es geschaft!.txt");
  20.     zip2.SetPassword(word.c_str());
  21.     bool success = zip2.OpenZip("Brut.zip");
  22.   if(!success)
  23.   {
  24.     cout << "TRY FOR '" << word << "' - FALSE" << endl;
  25.     return false;
  26.   } else {
  27.     cout << "TRY FOR '" << word << "' - TRUE" << endl;
  28.         int numFilesUnzipped = zip2.Unzip("extract");
  29.         if(numFilesUnzipped < 0)
  30.         {
  31.             cout << "PACK OUT ERROR" << endl;
  32.         }
  33.     return true;
  34.   }
  35. }
  36.      
  37. int main()
  38. {
  39.   /* --- informationen ---
  40.   * ziffern: 6
  41.   * buchstaben: abcdprsuw1234
  42.   */
  43.            
  44.   // --- parameter ---
  45.   char letters[] = "abcdprsuw1234";
  46.   int length = 6;
  47.            
  48.   // --- ausrechnen ---
  49.   int ziffern[length];
  50.   for(int i=0; i<length; i++) { ziffern[i] = 0; }
  51.            
  52.   int times = 1;
  53.   for(int i=0; i<length; i++) { times *= (sizeof(letters))-1; }
  54.            
  55.   // --- vordefinitionen ---
  56.   string word;
  57.   bool stop = false;
  58.            
  59.   for(int i=0; i<times; i++)
  60.   {
  61.     if(stop == false)
  62.     {
  63.       word = createWord(letters, ziffern);
  64.       if(testWord(word)) { stop = true; }
  65.       else
  66.       {
  67.         ziffern[sizeof(ziffern)-1]++;
  68.         for(int i=sizeof(ziffern); i>0; i--)
  69.         {
  70.             if(ziffern[i] == sizeof(letters))
  71.           {
  72.             ziffern[i] = 0;
  73.                         ziffern[i-1]++;
  74.           }
  75.         }
  76.         if(ziffern[0] == sizeof(letters))
  77.         {
  78.             cout << "ERROR: NO PASSWORD FOUND" << endl;
  79.             stop = true;
  80.         }
  81.       }
  82.     }
  83.   }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement