Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<string>
  3. #include<ctime>
  4.  
  5. using namespace std;
  6.  
  7. const char* book = { "1234567890" };
  8.  
  9. bool cmp(char *a, char *pass, int m)
  10. {
  11. string check, password = pass;
  12. for (int i = 0; i < m; i++)
  13. check += a[i];
  14. if (check != password) return false;
  15. return true;
  16. }
  17.  
  18. void Print(char *a, int n)
  19. {
  20. for (int i = 0; i < n; i++)
  21. cout << a[i];
  22. cout << endl;
  23. }
  24.  
  25. int ind(char a)
  26. {
  27. for (int i = 0; i < strlen(book); i++)
  28. if (a == book[i])
  29. return i;
  30. return -1;
  31. }
  32.  
  33. bool Set(char* a, int n, int m)
  34. {
  35. int j = m - 1;
  36. while (j >= 0 && a[j] == book[n - 1]) j--;
  37. if (j < 0)
  38. return false;
  39. if (a[j] == book[n - 1])
  40. j--;
  41. a[j] = book[ind(a[j])+1];
  42. if (j == m - 1)
  43. return true;
  44. for (int k = j + 1; k < m; k++)
  45. a[k] = book[0];
  46. return true;
  47. }
  48.  
  49. int main()
  50. {
  51. char* pass = new char();
  52. cout << "Pass: ";
  53. cin >> pass;
  54. int n = strlen(book), m = 1;
  55. char* a;
  56. bool flag = true;
  57.  
  58. int start = clock();
  59. while (flag)
  60. {
  61. a = new char[m];
  62. for (int i = 0; i < m; i++)
  63. a[i] = book[0];
  64. //Print(a, m);
  65. if (cmp(a, pass, m))
  66. {
  67. int end = clock();
  68. int t = (end - start) / CLOCKS_PER_SEC;
  69. cout << "Password: ";
  70. Print(a, m);
  71. cout << "time: " << t << endl;
  72. flag = false;
  73. }
  74.  
  75. while (Set(a, n, m)&&flag)
  76. {
  77. //Print(a, m);
  78. if (cmp(a, pass, m))
  79. {
  80. int end = clock();
  81. int t = (end - start) / CLOCKS_PER_SEC;
  82. cout << "Password: ";
  83. Print(a, m);
  84. cout << "time: " << t << endl;
  85. flag = false;
  86. }
  87. }
  88.  
  89. delete[] a;
  90. m++;
  91. }
  92.  
  93. getchar();
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement