Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include "iostream"
  3. #include "vector"
  4. #include "math.h"
  5. #include "string"
  6. #include "cstdlib"
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12.  
  13.     //min and max value of pass
  14.     unsigned int strMinLength = 8;
  15.     unsigned int strMaxLength = 15;
  16.     unsigned int strCrrLength = strMinLength;
  17.  
  18.     //pass that algorithm searches for
  19.     string pass = "matma010";
  20.  
  21.     //possible values
  22.     vector<char> chars;
  23.     for (size_t i = 48; i <= 57; i++)
  24.     {
  25.         chars.push_back(i);
  26.     }
  27.     for (size_t i = 65; i <= 90; i++)
  28.     {
  29.         chars.push_back(i);
  30.     }
  31.     for (size_t i = 97; i <= 126; i++)
  32.     {
  33.         chars.push_back(i);
  34.     }
  35.     const unsigned int charsAmount = chars.size();
  36.  
  37.     //vector containing iterartors for each char in pass
  38.     vector<int> counts;
  39.     for (size_t i = 0; i < strCrrLength; i++)
  40.     {
  41.         counts.push_back(0);
  42.     }
  43.  
  44.     //algorytm
  45.     while (strCrrLength <= strMaxLength)
  46.     {
  47.         unsigned int combinationAmoutn = pow(charsAmount, strCrrLength);
  48.  
  49.         for (size_t i = 1; i <= combinationAmoutn; i++)
  50.         {
  51.             string str;
  52.             for (size_t j = 0; j < strCrrLength; j++)
  53.             {
  54.                 str += chars[counts[j]];
  55.                 if (i % ((size_t)pow(charsAmount, j)) == 0) counts[j] = (counts[j] + 1) % charsAmount;
  56.             }
  57.             system("cls");
  58.             cout << str;
  59.             if (str == pass)
  60.             {
  61.                 system("cls");
  62.                 cout << "nice, your pass is: " << str << endl;
  63.                 system("pause");
  64.                 return 0;
  65.             }
  66.         }
  67.  
  68.         //preapering for next iteration
  69.         fill(counts.begin(), counts.end(), 0);
  70.         counts.push_back(0);
  71.     }
  72.  
  73.     cout << "nah, algorithm failed :/" << endl;
  74.     system("pause");
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement