Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<string>
- #include<ctime>
- using namespace std;
- const char* book = { "1234567890" };
- bool cmp(char *a, char *pass, int m)
- {
- string check, password = pass;
- for (int i = 0; i < m; i++)
- check += a[i];
- if (check != password) return false;
- return true;
- }
- void Print(char *a, int n)
- {
- for (int i = 0; i < n; i++)
- cout << a[i];
- cout << endl;
- }
- int ind(char a)
- {
- for (int i = 0; i < strlen(book); i++)
- if (a == book[i])
- return i;
- return -1;
- }
- bool Set(char* a, int n, int m)
- {
- int j = m - 1;
- while (j >= 0 && a[j] == book[n - 1]) j--;
- if (j < 0)
- return false;
- if (a[j] == book[n - 1])
- j--;
- a[j] = book[ind(a[j])+1];
- if (j == m - 1)
- return true;
- for (int k = j + 1; k < m; k++)
- a[k] = book[0];
- return true;
- }
- int main()
- {
- char* pass = new char();
- cout << "Pass: ";
- cin >> pass;
- int n = strlen(book), m = 1;
- char* a;
- bool flag = true;
- int start = clock();
- while (flag)
- {
- a = new char[m];
- for (int i = 0; i < m; i++)
- a[i] = book[0];
- //Print(a, m);
- if (cmp(a, pass, m))
- {
- int end = clock();
- int t = (end - start) / CLOCKS_PER_SEC;
- cout << "Password: ";
- Print(a, m);
- cout << "time: " << t << endl;
- flag = false;
- }
- while (Set(a, n, m)&&flag)
- {
- //Print(a, m);
- if (cmp(a, pass, m))
- {
- int end = clock();
- int t = (end - start) / CLOCKS_PER_SEC;
- cout << "Password: ";
- Print(a, m);
- cout << "time: " << t << endl;
- flag = false;
- }
- }
- delete[] a;
- m++;
- }
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement