Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include "md5.hpp"
  2.  
  3. #include <string>
  4.  
  5. #define MIN char(32)
  6. #define MAX char(126)
  7.  
  8. std::size_t first_not_max(
  9.     std::string& guess)
  10. {
  11.     std::size_t index = 0;
  12.  
  13.     for (char i : guess) {
  14.         if (i < MAX) {
  15.             break;
  16.         }
  17.         index++;
  18.     }
  19.  
  20.     return index;
  21. }
  22.  
  23. void increment_guess(
  24.     std::string& guess)
  25. {
  26.     std::size_t index = first_not_max(guess);
  27.  
  28.     if (index < guess.size()) {
  29.         guess[index]++;
  30.         if (index) {
  31.             memset(&guess[0], MIN, index);
  32.         }
  33.     } else {
  34.         guess.assign(guess.size()+1, MIN);
  35.     }
  36. }
  37.  
  38. int main() {
  39.     std::cout << "Enter MD5 to attempt to crack: ";
  40.     std::string hash;
  41.     std::getline(std::cin, hash);
  42.  
  43.     std::cout << std::endl << "Attempting brute force..." << std::endl << std::endl;
  44.  
  45.     std::string guess;
  46.  
  47.     guess += MIN;
  48.  
  49.     while (true) {
  50.         if (md5(guess) == hash) {
  51.             break;
  52.         }
  53.         increment_guess(guess);
  54.         if (guess.size() > 3) {
  55.             break;
  56.         }
  57.     }
  58.  
  59.     std::cout << "Result: " << guess << std::endl;
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement