Post
Topic
Board Bitcoin Discussion
Merits 1 from 1 user
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
denyAKA BLACKANGEL
on 20/04/2025, 06:57:26 UTC
⭐ Merited by xandry (1)
the code from zahid888 C++ its a lietl more faster




#include <iostream>
#include <fstream>
#include <vector>
#include <thread>
#include <mutex>
#include <atomic>
#include <random>
#include <unordered_set>
#include <string>
#include <iomanip>


constexpr int64_t START_SEED = 1706200000;
constexpr int64_t END_SEED = 10'000'000'000;
constexpr int BATCH_SIZE = 100'000;
const size_t NUM_THREADS = []() {
    unsigned cores = std::thread::hardware_concurrency();
    return cores > 50 ? cores : 80;
}();

std::mutex file_mutex;
std::atomic<int64_t> counter(START_SEED);
std::atomic<int> found_counter(0);
const std::unordered_set<uint32_t> TARGET_VALUES = {
    0xb862a62e, 0x9de820a7, 0xe9ae4933,
    0xe02b35a3, 0xade6d7ce, 0xefae164c,
    0x9d18b63a, 0xfc07a182, 0xf7051f27,
    0xbebb3940
};

void worker() {
    std::mt19937 gen;
    std::uniform_int_distribution<uint32_t> dist(0x80000000, 0xFFFFFFFF);
   
    while (true) {
        int64_t current_batch = counter.fetch_add(BATCH_SIZE);
        if (current_batch >= END_SEED) break;
       
        int64_t batch_end = std::min(current_batch + BATCH_SIZE, END_SEED);
        std::vector<std::pair<int64_t, uint32_t>> found;
       
        for (int64_t seed = current_batch; seed < batch_end; ++seed) {
            gen.seed(static_cast<uint32_t>(seed));
            uint32_t b = dist(gen);
           
            if (TARGET_VALUES.count(b)) {
                found.emplace_back(seed, b);
            }
        }
       
        if (!found.empty()) {
            std::lock_guard<std::mutex> lock(file_mutex);
            std::ofstream out("found_seeds.txt", std::ios::app);
            for (const auto& [seed, value] : found) {
                out << "seed: " << seed << " - FOUND! 0x"
                    << std::hex << std::setw(Cool << std::setfill('0') << value << "\n";
            }
            found_counter += found.size();
        }
    }
}

void print_progress() {
    const int64_t total = END_SEED - START_SEED;
    while (counter < END_SEED) {
        int64_t processed = counter - START_SEED;
        double percent = (processed * 100.0) / total;
       
        int bar_width = 50;
        int pos = bar_width * (percent / 100.0);
       
        std::cout << "\rProgress: [";
        for (int i = 0; i < bar_width; ++i) {
            std::cout << (i < pos ? "█" : "░");
        }
        std::cout << "] " << std::fixed << std::setprecision(2) << percent
                  << "% | Found: " << found_counter.load() << std::flush;
       
        std::this_thread::sleep_for(std::chrono::milliseconds(200));
    }
}

int main() {
    std::vector<std::thread> threads;
    std::cout << "Starting search with " << NUM_THREADS << " threads...\n";
   
    for (size_t i = 0; i < NUM_THREADS; ++i) {
        threads.emplace_back(worker);
    }
   
   
    std::thread progress_thread(print_progress);
   

    for (auto& t : threads) {
        t.join();
    }
   

    progress_thread.join();
   
    std::cout << "\n\nSearch complete. Found " << found_counter << " matches.\n";
    return 0;
}



you can compiling >>>>>>  g++ -O3 -std=c++17 -pthread seed_search.cpp -o seed_search