Post
Topic
Board Bitcoin Discussion
Re: Bitcoin puzzle transaction ~32 BTC prize to who solves it
by
fantom06
on 20/04/2025, 07:43:31 UTC
How do you generate the first two characters randomly? I mean on Kw, Ky, Kz, L1, L5 etc... Tongue

Code:
void generate_valid_prefix(char* output, Xoshiro256plus& rng) {

    char first_char = 'K' + (rng.next() % 2);
    char second_char = (first_char == 'K') ?
    BASE58[57 - (rng.next() % 10)] : BASE58[rng.next() % 5];
    output[0] = first_char;
    output[1] = second_char;
    output[2] = '\0';
}


or precomputed:

Code:
static const char VALID_PREFIXES[][3] = {
    "Kw", "Kx", "Ky", "Kz", "L1", "L2", "L3", "L4", "L5"
};

static constexpr size_t NUM_PREFIXES = sizeof(VALID_PREFIXES) / sizeof(VALID_PREFIXES[0]);

void generate_valid_prefix(char* output, Xoshiro256plus& rng) {
    // Generate a random index in [0, NUM_PREFIXES - 1]
    uint64_t random_index = rng.next() % NUM_PREFIXES;

    output[0] = VALID_PREFIXES[random_index][0];
    output[1] = VALID_PREFIXES[random_index][1];
    output[2] = '\0'; // Null terminator
}

 Wink

where to put this on wifhunter?