skindervik

HASH_CRACKER_V4

Jul 14th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.21 KB | None | 0 0
  1. #include<iostream>
  2. #include<math.h>
  3. #include<vector>
  4. #include<sstream>
  5. #include<openssl/sha.h>
  6. #include<iomanip>
  7. #include<thread>
  8. #include<atomic>
  9.  
  10. //VERIABLES FOR MULTI-THREADING
  11. bool finished = false;
  12. std::vector<std::thread> nodes;
  13.  
  14. //VERIABLES FOR SPEED CHECKING || UPDATES ONE TIME IN A SECOND
  15. long total_hash_count = 0;
  16. std::vector<bool> status_reported;
  17.  
  18.  
  19. void generate_them_all(int line, int thread_count, std::string what_is_this_hash) {
  20.  
  21.     //VERIABLES
  22.     char chars[] = { '0', '1','2','3','4','5','6','7','8','9', 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };
  23.     std::vector<int> password;
  24.  
  25.     //VERIABLES FOR SPEED REPORT
  26.     int ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  27.     int hash_count = 0;
  28.  
  29.     //VERIABLES FOR HASH
  30.     SHA256_CTX sha256;
  31.     std::stringstream hex_input;
  32.     std::stringstream hex_output;
  33.     unsigned char hash[SHA256_DIGEST_LENGTH];
  34.  
  35.     //SIZES OF VERIABLES
  36.     int chars_length = sizeof(chars) / sizeof(char);
  37.     int password_length = password.size();
  38.  
  39.     //MAKE SURE EVERY THREAD COUNTS DIFFERENT AMOUNT OF COMBINATIONS
  40.     for (size_t i = 0; i < line + 1; i++) // NEW
  41.         password.push_back(0);
  42.  
  43.  
  44.     //ADD AN ADDITIONAL CHARACTER TO PASSWORD VECTOR FOREVER IN A LOOP
  45.     while (true) {
  46.        
  47.  
  48.         //CYCKLE TROUGH ALL OF THE COMBINATIONS
  49.         for (int i = 0; i < pow(chars_length, password_length); i++) {
  50.  
  51.             //CYCKLE TROUGH ALL OF THE VERIABLES IN ARRAY
  52.             for (int i2 = 0; i2 < password_length; i2++) {
  53.                 //IF VERIABLE IN "PASSWORD" ARRAY IS THE LAST VERIABLE IN CHAR "CHARS" ARRRAY
  54.                 if (password[i2] == chars_length) {
  55.                     //THEN INCREMENT THE NEXT VERIABLE IN "PASSWORD" ARRAY
  56.                     password[i2 + 1]++;
  57.                     //AND RESET THE VERIABLE BACK TO ZERO
  58.                     password[i2] = 0;
  59.                 }
  60.             }
  61.  
  62.             //CLEAR hex_input and hex_output
  63.             hex_input.str("");
  64.             hex_output.str("");
  65.  
  66.             //CREATE THE COMBINATION
  67.             for (int i2 = 0; i2 < password_length; i2++) {
  68.                 hex_input << chars[password[i2]];
  69.             }
  70.  
  71.             //CREATE THE HASH
  72.             SHA256_Init(&sha256);
  73.             SHA256_Update(&sha256, hex_input.str().c_str(), hex_input.str().size());
  74.             SHA256_Final(hash, &sha256);
  75.  
  76.             //CONVERT HASH TO PROPER HEX
  77.             for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
  78.                 hex_output << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
  79.  
  80.             //PRINT OUT THE HASH
  81.             if (what_is_this_hash == hex_output.str()) {
  82.                 std::cout << hex_input.str() << " = " << hex_output.str() << std::endl;
  83.                 finished = true;
  84.             }
  85.            
  86.             //UPDATE SPEED REPORT
  87.             if (status_reported[line] == false) {
  88.                 int ms_now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
  89.                 if (ms <= ms_now - 1000) {
  90.                     ms = ms_now;
  91.                     total_hash_count += hash_count;
  92.                   //  std::cout << "thread-"<<line<< " = " << hash_count  <<std::endl;
  93.                     hash_count = 0;
  94.                    
  95.                     status_reported[line] = true;
  96.                 }
  97.             }
  98.             hash_count++;
  99.  
  100.             //INCREMENT THE FIRST VERIABLE IN ARRAY
  101.             password[0]++;
  102.         }
  103.        
  104.         //ADDS ANOTHER CHARACTER TO THE PASSWORD VECTOR
  105.         for (size_t i = 0; i < thread_count; i++) // NEW
  106.             password.push_back(0);
  107.  
  108.         //UPDATE THE SIZE OF THE PASSWORD VECTOR
  109.         password_length = password.size();
  110.  
  111.         //RESET PASSWORD VECTOR ELEMENTS BACK TO ZEROES
  112.         std::fill(password.begin(), password.end(), 0);
  113.     }
  114. }
  115.  
  116. int main() {
  117.     std::string hash_to_crack = "56a28b8ed9cb07b5488cd3a0d6fb3bcd50d47bd21a1a0c8b3300f002e659c0fe";
  118.  
  119.     //CHECK HOW MANY THREADS THE SYSTEM HAVE
  120.     auto thread_count = std::thread::hardware_concurrency();
  121.  
  122.     //CREATE THE THREADS
  123.     for (size_t i = 0; i < thread_count; i++){
  124.         nodes.push_back(std::thread(generate_them_all, i, thread_count, hash_to_crack));
  125.         status_reported.push_back(false);
  126.     }
  127.  
  128.     //VERY COMPLICATED WAY YO CHECK THE SPEED
  129.     while (finished == false) {
  130.        
  131.         bool all_finished = true;
  132.         for (size_t i = 0; i < thread_count; i++) {
  133.             if (status_reported[i] == false) {
  134.                 all_finished = false;
  135.             }
  136.         }
  137.         if (all_finished == true) {
  138.             std::cout << total_hash_count << " Mh/s\n";
  139.             total_hash_count = 0;
  140.             for (size_t i = 0; i < thread_count; i++) {
  141.                 status_reported[i] = false;
  142.             }
  143.         }
  144.         else
  145.             std::this_thread::sleep_for(std::chrono::milliseconds(10));
  146.     }
  147.     //
  148.  
  149.     system("pause");
  150.     quick_exit(0);
  151. }
Add Comment
Please, Sign In to add comment