Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<math.h>
- #include<vector>
- #include<sstream>
- #include<openssl/sha.h>
- #include<iomanip>
- #include<thread>
- #include<atomic>
- //VERIABLES FOR MULTI-THREADING
- bool finished = false;
- std::vector<std::thread> nodes;
- //VERIABLES FOR SPEED CHECKING || UPDATES ONE TIME IN A SECOND
- long total_hash_count = 0;
- std::vector<bool> status_reported;
- void generate_them_all(int line, int thread_count, std::string what_is_this_hash) {
- //VERIABLES
- 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' };
- std::vector<int> password;
- //VERIABLES FOR SPEED REPORT
- int ms = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- int hash_count = 0;
- //VERIABLES FOR HASH
- SHA256_CTX sha256;
- std::stringstream hex_input;
- std::stringstream hex_output;
- unsigned char hash[SHA256_DIGEST_LENGTH];
- //SIZES OF VERIABLES
- int chars_length = sizeof(chars) / sizeof(char);
- int password_length = password.size();
- //MAKE SURE EVERY THREAD COUNTS DIFFERENT AMOUNT OF COMBINATIONS
- for (size_t i = 0; i < line + 1; i++) // NEW
- password.push_back(0);
- //ADD AN ADDITIONAL CHARACTER TO PASSWORD VECTOR FOREVER IN A LOOP
- while (true) {
- //CYCKLE TROUGH ALL OF THE COMBINATIONS
- for (int i = 0; i < pow(chars_length, password_length); i++) {
- //CYCKLE TROUGH ALL OF THE VERIABLES IN ARRAY
- for (int i2 = 0; i2 < password_length; i2++) {
- //IF VERIABLE IN "PASSWORD" ARRAY IS THE LAST VERIABLE IN CHAR "CHARS" ARRRAY
- if (password[i2] == chars_length) {
- //THEN INCREMENT THE NEXT VERIABLE IN "PASSWORD" ARRAY
- password[i2 + 1]++;
- //AND RESET THE VERIABLE BACK TO ZERO
- password[i2] = 0;
- }
- }
- //CLEAR hex_input and hex_output
- hex_input.str("");
- hex_output.str("");
- //CREATE THE COMBINATION
- for (int i2 = 0; i2 < password_length; i2++) {
- hex_input << chars[password[i2]];
- }
- //CREATE THE HASH
- SHA256_Init(&sha256);
- SHA256_Update(&sha256, hex_input.str().c_str(), hex_input.str().size());
- SHA256_Final(hash, &sha256);
- //CONVERT HASH TO PROPER HEX
- for (int i = 0; i < SHA256_DIGEST_LENGTH; i++)
- hex_output << std::hex << std::setw(2) << std::setfill('0') << (int)hash[i];
- //PRINT OUT THE HASH
- if (what_is_this_hash == hex_output.str()) {
- std::cout << hex_input.str() << " = " << hex_output.str() << std::endl;
- finished = true;
- }
- //UPDATE SPEED REPORT
- if (status_reported[line] == false) {
- int ms_now = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
- if (ms <= ms_now - 1000) {
- ms = ms_now;
- total_hash_count += hash_count;
- // std::cout << "thread-"<<line<< " = " << hash_count <<std::endl;
- hash_count = 0;
- status_reported[line] = true;
- }
- }
- hash_count++;
- //INCREMENT THE FIRST VERIABLE IN ARRAY
- password[0]++;
- }
- //ADDS ANOTHER CHARACTER TO THE PASSWORD VECTOR
- for (size_t i = 0; i < thread_count; i++) // NEW
- password.push_back(0);
- //UPDATE THE SIZE OF THE PASSWORD VECTOR
- password_length = password.size();
- //RESET PASSWORD VECTOR ELEMENTS BACK TO ZEROES
- std::fill(password.begin(), password.end(), 0);
- }
- }
- int main() {
- std::string hash_to_crack = "56a28b8ed9cb07b5488cd3a0d6fb3bcd50d47bd21a1a0c8b3300f002e659c0fe";
- //CHECK HOW MANY THREADS THE SYSTEM HAVE
- auto thread_count = std::thread::hardware_concurrency();
- //CREATE THE THREADS
- for (size_t i = 0; i < thread_count; i++){
- nodes.push_back(std::thread(generate_them_all, i, thread_count, hash_to_crack));
- status_reported.push_back(false);
- }
- //VERY COMPLICATED WAY YO CHECK THE SPEED
- while (finished == false) {
- bool all_finished = true;
- for (size_t i = 0; i < thread_count; i++) {
- if (status_reported[i] == false) {
- all_finished = false;
- }
- }
- if (all_finished == true) {
- std::cout << total_hash_count << " Mh/s\n";
- total_hash_count = 0;
- for (size_t i = 0; i < thread_count; i++) {
- status_reported[i] = false;
- }
- }
- else
- std::this_thread::sleep_for(std::chrono::milliseconds(10));
- }
- //
- system("pause");
- quick_exit(0);
- }
Add Comment
Please, Sign In to add comment