Post
Topic
Board Development & Technical Discussion
Merits 1 from 1 user
Re: A probabilistic prefix search - puzzle btc 32
by
mcdouglasx
on 15/02/2025, 18:36:08 UTC
⭐ Merited by iceland2k14 (1)
how are u sure if the partial match exist the target is in that range?


You can't be sure of anything in probabilistic software. The less probable ranges are discarded, but saying 'it's less probable' doesn't guarantee your success 100%.

I just can not understand what this code represent... And how to use it

It's just a probabilistic script that omits certain sub-ranges where a prefix has already appeared.

Give a demonstration

Given that the probability of obtaining the first 4 digits of a hex "abcd" is 1/65536, the probability of finding 5 repeated prefixes "abcde" within the same range occurs with at least a 3% frequency. Therefore, if we discard 65536 keys around a 5-digit prefix, we have a 97% probability that the prefix is not within the omitted range.

This takes into account all prefixes and combinations within a given range. However, when choosing a specific prefix, the probabilities of approximation are much lower, as you add a known factor or element to the statistics and probabilities.


As you increase the length of the prefix n, the probability of two prefixes of n characters colliding nearby decreases.

Of all the possible combinations of 5 prefixes (16**5=1,048,576) in 65,537 keys, you get approximately 2000 collisions.


Test script:

Code:
import secp256k1 as ice
import random

pref_dict = {}
rand = random.randint(1, 2**256)

for i in range(1, 65537):
    x = ice.privatekey_to_h160(0, 1, rand + i).hex()
    prefix = x[:5]
    sav = str(x) + " = " + str(i) + "\n"
    if prefix not in pref_dict:
        pref_dict[prefix] = []
    pref_dict[prefix].append(sav)

entries = []
for prefix in sorted(pref_dict):
    if len(pref_dict[prefix]) > 1:
        entries.extend(pref_dict[prefix])

entries.sort()

with open('output.txt', 'w') as f:
    for entry in entries:
        f.write(entry)