Guest User

main.cpp

a guest
Mar 24th, 2021
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3.  
  4. bool nextPermutationStr(std::string& s)
  5. {
  6.     int sumIndex = 0;
  7.     while (s[sumIndex] == 122)
  8.     {
  9.         ++sumIndex;
  10.         if (sumIndex == s.length())
  11.             return false;
  12.     }
  13.  
  14.     ++s[sumIndex];
  15.     for (int i = 0; i < sumIndex; ++i)
  16.         s[i] = 97;
  17.  
  18.     return true;
  19. }
  20.  
  21. int main()
  22. {
  23.     std::string passwordTarget = "kgpggr";
  24.     std::string passwordStart = "aaaaaa";
  25.  
  26.     do
  27.     {
  28.         if (passwordStart == passwordTarget)
  29.             std::cout << "Password cracked: " << passwordTarget << std::endl;
  30.     } while (nextPermutationStr(passwordStart));
  31.  
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment