skindervik

HASH_CRACKER_V3

Jul 14th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.10 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.  
  8. int main() {
  9.  
  10.     //VERIABLES
  11.     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' };
  12.     std::vector<int> password = { 0 };
  13.     //
  14.     SHA256_CTX sha256; //NEW
  15.     std::stringstream hex_input; //NEW
  16.     std::stringstream hex_output; //NEW
  17.     unsigned char hash[SHA256_DIGEST_LENGTH]; //NEW
  18.  
  19.     //SIZES OF VERIABLES
  20.     int chars_length = sizeof(chars) / sizeof(char);
  21.     int password_length = password.size();
  22.  
  23.     //ADD AN ADDITIONAL CHARACTER TO PASSWORD VECTOR FOREVER IN A LOOP
  24.     while (true) {
  25.  
  26.         //CYCKLE TROUGH ALL OF THE COMBINATIONS
  27.         for (int i = 0; i < pow(chars_length, password_length); i++) {
  28.  
  29.             //CYCKLE TROUGH ALL OF THE VERIABLES IN ARRAY
  30.             for (int i2 = 0; i2 < password_length; i2++) {
  31.                 //IF VERIABLE IN "PASSWORD" ARRAY IS THE LAST VERIABLE IN CHAR "CHARS" ARRRAY
  32.                 if (password[i2] == chars_length) {
  33.                     //THEN INCREMENT THE NEXT VERIABLE IN "PASSWORD" ARRAY
  34.                     password[i2 + 1]++;
  35.                     //AND RESET THE VERIABLE BACK TO ZERO
  36.                     password[i2] = 0;
  37.                 }
  38.             }
  39.  
  40.             //#####NEW#####
  41.             //CLEAR hex_input and hex_output
  42.             hex_input.str("");
  43.             hex_output.str("");
  44.  
  45.             //CREATE THE COMBINATION
  46.             for (int i2 = 0; i2 < password_length; i2++) {
  47.                 hex_input << chars[password[i2]];
  48.             }
  49.            
  50.             //CREATE THE HASH
  51.             SHA256_Init(&sha256);
  52.             SHA256_Update(&sha256, hex_input.str().c_str(), hex_input.str().size());
  53.             SHA256_Final(hash, &sha256);
  54.  
  55.             //CONVERT HASH TO PROPER HEX
  56.             for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
  57.             {
  58.                 hex_output << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
  59.             }
  60.  
  61.             //PRINT OUT THE HASH
  62.             std::cout << hex_input.str() << " = " << hex_output.str() << std::endl;
  63.             //#############
  64.  
  65.             //std::cout << i << ": ";                          //DELETED
  66.             //for (int i2 = 0; i2 < password_length; i2++) {   //DELETED
  67.             //    std::cout << chars[password[i2]] << " ";     //DELETED
  68.             //}                                                //DELETED
  69.             //std::cout << "\n";                               //DELETED
  70.  
  71.             //INCREMENT THE FIRST VERIABLE IN ARRAY
  72.             password[0]++;
  73.         }
  74.  
  75.         //ADDS ANOTHER CHARACTER TO THE PASSWORD VECTOR
  76.         password.push_back(0);
  77.  
  78.         //UPDATE THE SIZE OF THE PASSWORD VECTOR
  79.         password_length = password.size();
  80.  
  81.         //RESET PASSWORD VECTOR ELEMENTS BACK TO ZEROES
  82.         std::fill(password.begin(), password.end(), 0);
  83.     }
  84. }
Add Comment
Please, Sign In to add comment