Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "iostream"
- #include "vector"
- #include "math.h"
- #include "string"
- #include "cstdlib"
- using namespace std;
- int main()
- {
- //min and max value of pass
- unsigned int strMinLength = 8;
- unsigned int strMaxLength = 15;
- unsigned int strCrrLength = strMinLength;
- //pass that algorithm searches for
- string pass = "matma010";
- //possible values
- vector<char> chars;
- for (size_t i = 48; i <= 57; i++)
- {
- chars.push_back(i);
- }
- for (size_t i = 65; i <= 90; i++)
- {
- chars.push_back(i);
- }
- for (size_t i = 97; i <= 126; i++)
- {
- chars.push_back(i);
- }
- const unsigned int charsAmount = chars.size();
- //vector containing iterartors for each char in pass
- vector<int> counts;
- for (size_t i = 0; i < strCrrLength; i++)
- {
- counts.push_back(0);
- }
- //algorytm
- while (strCrrLength <= strMaxLength)
- {
- unsigned int combinationAmoutn = pow(charsAmount, strCrrLength);
- for (size_t i = 1; i <= combinationAmoutn; i++)
- {
- string str;
- for (size_t j = 0; j < strCrrLength; j++)
- {
- str += chars[counts[j]];
- if (i % ((size_t)pow(charsAmount, j)) == 0) counts[j] = (counts[j] + 1) % charsAmount;
- }
- system("cls");
- cout << str;
- if (str == pass)
- {
- system("cls");
- cout << "nice, your pass is: " << str << endl;
- system("pause");
- return 0;
- }
- }
- //preapering for next iteration
- fill(counts.begin(), counts.end(), 0);
- counts.push_back(0);
- }
- cout << "nah, algorithm failed :/" << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement