Can anyone explain to me the concept or link me some source that explains how can vanitygen find a pattern in an unreversible hash?
It's clearly following some search pattern that isn't just trying out random private keys and hoping to find the desired pattern. People can let it run for weeks to find a 8-char pattern for example. And it'll slowly display the probability percentage until it finds one. I'd like to know the maths behind that if anyone can give me a clue, cheers.
First you need to know how the 8 bit (byte 00) + 160 bit (ripemd160) + 32 bit (checksum) of an address are encoded in base58 :
https://bitcoin.stackexchange.com/questions/48586/best-way-to-calculate-difficulty-of-generating-specific-vanity-addressYou got so far some inaccurate answers.
For each 22 addresses there is an address that starts with 1A, so we say that the difficulty of the prefix 1A is 22 (= number of addresses you have to generate on average to get a match).
Instead the difficulty of the prefix 11 is 256, i.e. 11xxx addresses are less than 1/10th of the 1Axxx addresses.
The formula 58^n is not correct at all, because
the 58 characters don't have the same chance of happening.
How does vanitygen compute the probability?
Let's do an example with 1A prefix. Let T be the target set of the addresses 1Axxxxx. To get on average 1 match we have to generate 22 addresses.
Smaller is the target, bigger is the difficulty to hitting it and viceversa.
Let me rephrase this:
difficulty * size of target = search space, in our case a small difficulty and therefore a big target ( it's easy to hit this target!):
22 * 63703009616853067642911677093369144589991624155 = 2^160
number of keys we have to use (= numbers of addresses we have to generate to get on average 1 match) * number of addresses in T = 2^160 possible addresses.
Every time we try a new private key, we have 1 chance over 22 to hit our target set T (the probability is 1/22). At every roll then we don't hit the set T with probability 1 - 1/22. If we use k private keys, we don't hit T with probability (21/22)^k.
The probability of hitting T in k trials is then:
P = 1 - (21/22)^khttps://en.wikipedia.org/wiki/Geometric_distributionThe geometric distribution gives the probability that the first occurrence of success requires k independent trials, each with success probability p. If the probability of success on each trial is p, then the probability that the kth trial (out of k trials) is the first success is
P(X=k) = p(1-p)^(k-1) for k = 1, 2, 3, ....
The cumulative distribution function is P(X<=k) = 1 - (1-p)^k (it is the probability that X will take a value less than or equal to k ).
If we want to have :
a 50% chance, 1 - (21/22)^k = 0.50 --> k = log(0.50)/log(21/22) = 14.9 tries (not 11!)
a 64% chance, 1 - (21/22)^k = 0.64 --> k = log(0.36)/log(21/22) = 22.0 tries
a 75% chance, 1 - (21/22)^k = 0.75 --> k = log(0.25)/log(21/22) = 29.8 tries (not 11!)
a 90% chance, 1 - (21/22)^k = 0.90 --> k = log(0.10)/log(21/22) = 49.5 tries
a 95.5% chance, 1 - (21/22)^k = 0.955 --> k = log(0.045)/log(21/22) = 66.7 tries (3 times 22!!)
a 99% chance, 1 - (21/22)^k = 0.99 --> k = log(0.01)/log(21/22) = 99 tries
and so on (100% only for k -> infinity).
On average it takes 22 tries to get 1 match, but if you do 22 tries
only once you will have only a 64% chance to get a match!
And vanitygen computes right the probability to find a match in the particular sequence you are running, vanitygen doesn't compute anything "on average".