<<  >> (p.191)
    Author Topic: Bitcoin puzzle transaction ~32 BTC prize to who solves it  (Read 324360 times)
    rosengold
    Jr. Member
    *
    Offline Offline

    Activity: 149
    Merit: 7


    View Profile
    October 25, 2023, 05:47:36 PM
     #3801


    Code:
    #include <iostream>
    #include <vector>...

    • Bytea HASH160 Search by NoMachine
    • Sat Oct 21 10:39:23 2023
    • Puzzle: 15
    • Public Key Hash (Hash 160): fe7c45126731f7384640b0b0045fd40bac72e2a2
    • PUZZLE SOLVED: 2023-10-21 10:39:24
    • Target Public Key Hash (Hash160) found! Private Key: 00000000000000000000000000000000000000000
    Hi @nomachine

    how to make it work sequential instead of random ?




    here you go,  buddy

    Code:
    #include <iostream>
    #include <vector>
    #include <iomanip>
    #include <openssl/bn.h>
    #include <openssl/ec.h>
    #include <openssl/obj_mac.h>
    #include <openssl/sha.h>
    #include <openssl/evp.h>
    #include <openssl/ripemd.h>
    #include <ctime>
    #include <sstream>
    #include <fstream>

    // Function to convert a byte vector to a hexadecimal string
    std::string bytesToHex(const std::vector<unsigned char>& bytes) {
        std::stringstream ss;
        for (unsigned char byte : bytes) {
            ss << std::hex << std::setw(2) << std::setfill('0') << static_cast<int>(byte);
        }
        return ss.str();
    }

    // Function to calculate the RIPEMD160 hash of a byte vector
    std::vector<unsigned char> calculateRIPEMD160(const std::vector<unsigned char>& data) {
        std::vector<unsigned char> hash(RIPEMD160_DIGEST_LENGTH);
        RIPEMD160(data.data(), data.size(), hash.data());
        return hash;
    }

    int main() {
        // Initialize the OpenSSL library
        if (OpenSSL_add_all_algorithms() != 1) {
            std::cerr << "OpenSSL initialization failed." << std::endl;
            return 1;
        }

        // Define the range
        std::string start_range_hex = "000000000000000000000000000000000000000000000001ffffffffffffffff";
        std::string end_range_hex = "000000000000000000000000000000000000000000000003ffffffffffffffff";
        // Set the target Hash160 value (replace with your target hash)
        std::string target_hash160_hex = "20d45a6a762535700ce9e0b216e31994335db8a5";

        // Create an EC_KEY object
        EC_KEY* ec_key = EC_KEY_new_by_curve_name(NID_secp256k1);

        // Calculate the SHA-256 hash of the public key
        unsigned char sha256_result[SHA256_DIGEST_LENGTH];

        // Calculate the RIPEMD160 hash of the SHA-256 hash
        std::vector<unsigned char> ripemd160_result(RIPEMD160_DIGEST_LENGTH);

        BIGNUM* start_range = BN_new();
        BIGNUM* end_range = BN_new();
        BN_hex2bn(&start_range, start_range_hex.c_str());
        BN_hex2bn(&end_range, end_range_hex.c_str());

        while (BN_cmp(start_range, end_range) <= 0) {
            // Create a BIGNUM from the current value in the range
            BIGNUM* bn_private_key = BN_dup(start_range);

            // Set the private key in the EC_KEY object
            EC_KEY_set_private_key(ec_key, bn_private_key);

            // Compute the public key from the private key
            EC_POINT* public_key_point = EC_POINT_new(EC_KEY_get0_group(ec_key));
            EC_POINT_mul(EC_KEY_get0_group(ec_key), public_key_point, bn_private_key, NULL, NULL, NULL);

            // Convert the public key point to binary representation (compressed)
            size_t public_key_length = EC_POINT_point2oct(EC_KEY_get0_group(ec_key), public_key_point, POINT_CONVERSION_COMPRESSED, NULL, 0, NULL);
            std::vector<unsigned char> public_key_bytes(public_key_length);
            EC_POINT_point2oct(EC_KEY_get0_group(ec_key), public_key_point, POINT_CONVERSION_COMPRESSED, public_key_bytes.data(), public_key_length, NULL);

            SHA256(public_key_bytes.data(), public_key_bytes.size(), sha256_result);
            ripemd160_result = calculateRIPEMD160(std::vector<unsigned char>(sha256_result, sha256_result + SHA256_DIGEST_LENGTH));

            // Convert the calculated RIPEMD160 hash to a hexadecimal string
            std::string calculated_hash160_hex = bytesToHex(ripemd160_result);

            // Display the generated public key hash (Hash160) and private key
            std::string message = "\r\033[01;33m[+] Public Key Hash (Hash 160): " + calculated_hash160_hex;
            std::cout << message << "\e[?25l";
            std::cout.flush();

            // Check if the generated public key hash matches the target
            if (calculated_hash160_hex == target_hash160_hex) {
                // Get the current time
                std::time_t currentTime;
                std::time(&currentTime);
                std::tm tmStruct = *std::localtime(&currentTime);

                // Format the current time into a human-readable string
                std::stringstream timeStringStream;
                timeStringStream << std::put_time(&tmStruct, "%Y-%m-%d %H:%M:%S");
                std::string formattedTime = timeStringStream.str();

                std::cout << "\n\033[32m[+] PUZZLE SOLVED: " << formattedTime << "\033[0m" << std::endl;
                std::cout << "\r\033[32m[+] Target Public Key Hash (Hash160) found! Private Key: " << BN_bn2hex(bn_private_key) << std::endl;

                // Append the private key information to a file if it matches
                std::ofstream file("KEYFOUNDKEYFOUND.txt", std::ios::app);
                if (file.is_open()) {
                    file << "\nPUZZLE SOLVED " << formattedTime;
                    file << "\nPrivate Key (hex): " << BN_bn2hex(bn_private_key);
                    file << "\n--------------------------------------------------------------------------------------------------------------------------------------------";
                    file.close();
                }

                BN_free(bn_private_key);
                break;
            }

            // Increment the current value in the range
            BN_add_word(start_range, 1);
        }

        // Free the EC_KEY and BIGNUM objects
        BN_free(start_range);
        BN_free(end_range);
        EC_KEY_free(ec_key);

        return 0;
    }

    Code:
    g++ -m64 -march=native -pthread -O3 -I. -o puzzle66 puzzle.cpp -lssl -lcrypto -ldl




    Amazing thanks
Page 190
Viewing Page: 191