<blockquote>
<p><strong>how is it possible that we can know that a private key that starts with 'S' and which we added a question mark will result in a hash that starts with '00' byte?</strong></p>
</blockquote>
<p>The text you quoted includes this:</p>
<blockquote>
<p>A user brute forces the process using random numbers until a well-formatted mini private key is produced.</p>
</blockquote>
<p>So I guess the initial mini-private-key is the result of a lot of attempts to produce a value with that characteristic.</p>
<p>I think that if you take &quot;S&quot;, append 29 random characters (from the base58 character set) and append &quot;?&quot; then take the hash, there is a 1 in 256 chance the resulting hash will have 0x00 as its first byte. So you probably only have to try around 256 attempts on average to create a valid private mini key.</p>
<p>In pseudo-code</p>
<pre><code>func create_minikey() string {
  repeat
     attempt := &quot;s&quot; + random(29, base58)
  until (hash(attempt + &quot;?&quot;))[0] == 0
  return attempt
}
</code></pre>

CC BY-SA 4.0
2022-10-10T22:27:37.563Z
2022-10-10T22:45:22.913Z
2022-10-10T22:45:22.913Z
RedGrittyBrick
<p>In the bitcoin developer wallet guide, when talking about Mini Private Key Format, when they explain how the format works, they describe some steps:</p>
<blockquote>
<ol>
<li><p>The first character of mini keys is ‘S’.</p>
</li>
<li><p>In order to determine if a mini private key is well-formatted, a question mark is added to the private key.</p>
</li>
<li><p>The SHA256 hash is calculated. If the first byte produced is a `00’, it is well-formatted. This key restriction acts as a
typo-checking mechanism. A user brute forces the process using random
numbers until a well-formatted mini private key is produced.</p>
</li>
<li><p>In order to derive the full private key, the user simply takes a single SHA256 hash of the original mini private key. This process is
one-way: it is intractable to compute the mini private key format from
the derived key.</p>
</li>
</ol>
</blockquote>
<p>What I do not understand is step 1 and 2 combined with step 3, if a hash function such as sha256 is irreversible, this is, given its output we cannot guess its input, how is it possible that we can know that a private key that starts with 'S' and which we added a question mark will result in a hash that starts with '00' byte?</p>
<p>Can people extract input formats knowing that it will output certain characters in certain positions?</p>
<p>Is it not one of the pros of hashes that a minimum change in the input will transform the whole output?</p>
<p>How can someone assure that with step 1 and 2, you will get '00' byte, when if a change is made over the left hash input characters, it will completely change?</p>

<wallet><private-key><hash>
How can we know the first bytes of a hash for a given input format string?
javi11br
# How can we know the first bytes of a hash for a given input format string?

(Asked by: username_0 on 2022-10-10)

In the bitcoin developer wallet guide, when talking about Mini Private Key Format, when they explain how the format works, they describe some steps:

> 1. The first character of mini keys is ‘S’.
> 2. In order to determine if a mini private key is well-formatted, a question mark is added to the private key.
> 3. The SHA256 hash is calculated. If the first byte produced is a `00’, it is well-formatted. This key restriction acts as a
>    typo-checking mechanism. A user brute forces the process using random
>    numbers until a well-formatted mini private key is produced.
> 4. In order to derive the full private key, the user simply takes a single SHA256 hash of the original mini private key. This process is
>    one-way: it is intractable to compute the mini private key format from
>    the derived key.

What I do not understand is step 1 and 2 combined with step 3, if a hash function such as sha256 is irreversible, this is, given its output we cannot guess its input, how is it possible that we can know that a private key that starts with 'S' and which we added a question mark will result in a hash that starts with '00' byte?

Can people extract input formats knowing that it will output certain characters in certain positions?

Is it not one of the pros of hashes that a minimum change in the input will transform the whole output?

How can someone assure that with step 1 and 2, you will get '00' byte, when if a change is made over the left hash input characters, it will completely change?

**Tags:** wallet, private-key, hash


---

## 1 answers

### Answer by username_1 on 2022-10-10. Score: 1

> **how is it possible that we can know that a private key that starts with 'S' and which we added a question mark will result in a hash that starts with '00' byte?**

The text you quoted includes this:

> A user brute forces the process using random numbers until a well-formatted mini private key is produced.

So I guess the initial mini-private-key is the result of a lot of attempts to produce a value with that characteristic.

I think that if you take "S", append 29 random characters (from the base58 character set) and append "?" then take the hash, there is a 1 in 256 chance the resulting hash will have 0x00 as its first byte. So you probably only have to try around 256 attempts on average to create a valid private mini key.

In pseudo-code

```
func create_minikey() string {
  repeat
     attempt := "s" + random(29, base58)
  until (hash(attempt + "?"))[0] == 0
  return attempt
}

```


---

