Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
nomachine
on 29/05/2024, 19:21:11 UTC
I searched and couldn't find anything in C++.

You can use VanitySearch to generate whatever you want if you know how  Grin

Code:
git clone https://github.com/JeanLucPons/VanitySearch.git

For example

main.cpp

Code:
#include "SECP256k1.h"
#include "Int.h"
#include <iostream>
#include <fstream>
#include <string>
#include <ctime>
#include <iomanip>
#include <sstream>
#include <thread>
#include <vector>
#include <mutex>
#include <memory>
#include <algorithm>

const int numThreads =  128;  // You can adjust this number based on your CPU cores

// Function to generate keys and check for a specific public key
void generateKeysAndCheckForPublicKey(const Int& minKey, Int maxKey, std::shared_ptr<Secp256K1> secp256k1, const std::string& targetPublicKey) {
    Int privateKey = minKey;
    Point publicKey;
    std::string pubKeyStr;
    std::string wifc;

    while (true) {
        publicKey = secp256k1->ComputePublicKey(&privateKey);
        pubKeyStr = secp256k1->GetPublicKeyHex(true, publicKey);  //  get the public key in hex format
       
        // Convert pubKeyStr to lowercase
        std::transform(pubKeyStr.begin(), pubKeyStr.end(), pubKeyStr.begin(), ::tolower);
       
        wifc = secp256k1->GetPrivAddress(true, privateKey);
       
        // Display the generated public key
        std::string message = "\r\033[01;33m[+] " + pubKeyStr;
        std::cout << message << "\e[?25l";
        std::cout.flush();

        // Check if the generated public key matches the target public key
        if (pubKeyStr == targetPublicKey) {
            time_t currentTime = std::time(nullptr);

            // Format the current time into a human-readable string
            std::tm tmStruct = *std::localtime(&currentTime);
            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 << "\033[32m[+] WIF: " << wifc << "\033[0m" << 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 << "\nPublic Key: " << pubKeyStr;
                file << "\nPrivatekey (dec): " << privateKey.GetBase10();
                file << "\nPrivatekey Compressed (wif): " << wifc;
                file << "\n----------------------------------------------------------------------------------------------------------------------------------";
                file.close();
            }
        }

        privateKey.AddOne();

        if (privateKey.IsGreater(&maxKey)) {
            break;
        }
    }
}

int main() {
    // Clear the console
    std::system("clear");

    time_t currentTime = std::time(nullptr);
    std::cout << "\033[01;33m[+] " << std::ctime(&currentTime) << "\r";
    std::cout.flush();

    Int minKey;
    Int maxKey;
    // Configuration for the Puzzle 20
    minKey.SetBase10("524287");
    maxKey.SetBase10("1048575");
    std::string targetPublicKey = "033c4a45cbd643ff97d77f41ea37e843648d50fd894b864b0d52febc62f6454f7c"; // Puzzle 20 public key

    // Initialize SECP256k1
    std::shared_ptr<Secp256K1> secp256k1 = std::make_shared<Secp256K1>();
    secp256k1->Init();

    // Create threads for key generation and checking
    std::vector<std::thread> threads;

    for (int i = 0; i < numThreads; ++i) {
        threads.emplace_back(generateKeysAndCheckForPublicKey, minKey, maxKey, secp256k1, targetPublicKey);
    }

    // Wait for all threads to finish
    for (std::thread& thread : threads) {
        thread.join();
    }

    return 0;
}

copy and paste this into main.cpp

make

./VanitySearch

  • PUZZLE SOLVED: 2024-05-29 21:20:42
  • WIF: KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rHfuE2Tg4nJW