<blockquote>
<p>The SHA-256 hash of the hex string is 5355d54a3d673c4b1ac20b839ead09af3c6fea6dc24199b477f6ff64e7a68262. The first 4 bits of that are represented by the first hex character, 5, which in binary is 0101.</p>
</blockquote>
<p>You need to take the shasum of the raw binary, not the hex string:</p>
<pre><code>$ echo &quot;11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010&quot; | shasum -a 256 -b
</code></pre>
<p>Gives output</p>
<p><code>3043b02ceb37bb00ab48c91f76bb23d487e1ec822c90e1575967e8838a655f7c *-</code></p>
<p>When converting this hexstring to binary we get:</p>
<p><code>0011000001000011101100000010110011101011001101111011101100000000101010110100100011001001000111110111011010111011001000111101010010000111111000011110110010000010001011001001000011100001010101110101100101100111111010001000001110001010011001010101111101111100</code></p>
<p>The first four bits of this string are <code>0011</code>, which is consistent with the output given by the Ian Coleman tool.</p>

CC BY-SA 4.0
2020-11-01T01:06:24.287Z
2020-11-01T01:06:24.287Z
chytrik
<p>when I want &quot;$ echo &quot;11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010&quot; | shasum -a 256 -b&quot; convert python language to &quot;sha256_hash = hashlib.sha256(data.encode()).hexdigest()&quot;, it return &quot;7529ea5a2f86b91b4b72e41aa36c190e8173e2fef6bbda828f74e55022eefec8&quot;, wrong result, BUT I don't know which error came from?</p>

CC BY-SA 4.0
2024-04-20T17:54:13.557Z
2024-04-20T17:54:13.557Z
王铎霖
<p>I'm trying to find the checksum for a 12-word BIP39.</p>
<p>I can find the first eleven words just fine, but my 12th word is always off by a few positions.</p>
<p>For example, take the 128-bit entropy <code>e84eaa26330ccbb2f866a1dc155e94ba</code>.</p>
<p>In binary that is <code>11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010</code>.</p>
<p>The first eleven 11-bit words are:</p>
<pre><code>11101000010 (bin) =&gt; 1858 (decimal) =&gt; tribe
01110101010 (bin) =&gt; 938  (decimal) =&gt; inspire
10001001100 (bin) =&gt; 1100 (decimal) =&gt; maze
01100110000 (bin) =&gt; 816  (decimal) =&gt; gravity
11001100101 (bin) =&gt; 1637 (decimal) =&gt; smile
11011001011 (bin) =&gt; 1739 (decimal) =&gt; sunny
11100001100 (bin) =&gt; 1804 (decimal) =&gt; thunder
11010100001 (bin) =&gt; 1697 (decimal) =&gt; stage
11011100000 (bin) =&gt; 1760 (decimal) =&gt; swing
10101010111 (bin) =&gt; 1367 (decimal) =&gt; priority
10100101001 (bin) =&gt; 1321 (decimal) =&gt; pioneer
</code></pre>
<p>There are still 7 unused bits, the last ones: <code>0111010</code>.</p>
<p>The SHA-256 hash of the hex string is <code>5355d54a3d673c4b1ac20b839ead09af3c6fea6dc24199b477f6ff64e7a68262</code>.
The first 4 bits of that are represented by the first hex character, <code>5</code>, which in binary is <code>0101</code>.</p>
<p>I append those 4 bytes to my binary string:
<code>111010000100111010101010001001100011001100001100110010111011001011111000011001101010000111011100000101010101111010010100101110100101</code></p>
<p>Now I have the last 11-bit word:</p>
<pre><code>01110100101 (bin) =&gt; 933 (decimal) =&gt; input
</code></pre>
<p>But when I try to validate that against <a href="https://iancoleman.io/bip39/" rel="nofollow noreferrer">Ian Coleman's Bip39</a> I see the checksum should be <code>0011</code> (not <code>0101</code>) and that would make the last word be</p>
<pre><code>01110100011 (bin) =&gt; 931 (decimal) =&gt; inner
</code></pre>
<p>What am I doing wrong?</p>

<mnemonic-seed><checksum>
Pseudo code to find Bip39 checksum?
Daniel Portugal
# Pseudo code to find Bip39 checksum?

(Asked by: username_0 on 2020-10-31)

I'm trying to find the checksum for a 12-word BIP39.

I can find the first eleven words just fine, but my 12th word is always off by a few positions.

For example, take the 128-bit entropy `e84eaa26330ccbb2f866a1dc155e94ba`.

In binary that is `11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010`.

The first eleven 11-bit words are:

```
11101000010 (bin) => 1858 (decimal) => tribe
01110101010 (bin) => 938  (decimal) => inspire
10001001100 (bin) => 1100 (decimal) => maze
01100110000 (bin) => 816  (decimal) => gravity
11001100101 (bin) => 1637 (decimal) => smile
11011001011 (bin) => 1739 (decimal) => sunny
11100001100 (bin) => 1804 (decimal) => thunder
11010100001 (bin) => 1697 (decimal) => stage
11011100000 (bin) => 1760 (decimal) => swing
10101010111 (bin) => 1367 (decimal) => priority
10100101001 (bin) => 1321 (decimal) => pioneer

```

There are still 7 unused bits, the last ones: `0111010`.

The SHA-256 hash of the hex string is `5355d54a3d673c4b1ac20b839ead09af3c6fea6dc24199b477f6ff64e7a68262`.
The first 4 bits of that are represented by the first hex character, `5`, which in binary is `0101`.

I append those 4 bytes to my binary string:
`111010000100111010101010001001100011001100001100110010111011001011111000011001101010000111011100000101010101111010010100101110100101`

Now I have the last 11-bit word:

```
01110100101 (bin) => 933 (decimal) => input

```

But when I try to validate that against [Ian Coleman's Bip39](https://iancoleman.io/bip39/) I see the checksum should be `0011` (not `0101`) and that would make the last word be

```
01110100011 (bin) => 931 (decimal) => inner

```

What am I doing wrong?

**Tags:** mnemonic-seed, checksum


---

## 2 answers

### Answer by username_1 on 2020-11-01. Score: 3 | Accepted answer

> The SHA-256 hash of the hex string is 5355d54a3d673c4b1ac20b839ead09af3c6fea6dc24199b477f6ff64e7a68262. The first 4 bits of that are represented by the first hex character, 5, which in binary is 0101.

You need to take the shasum of the raw binary, not the hex string:

```
$ echo "11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010" | shasum -a 256 -b

```

Gives output

`3043b02ceb37bb00ab48c91f76bb23d487e1ec822c90e1575967e8838a655f7c *-`

When converting this hexstring to binary we get:

`0011000001000011101100000010110011101011001101111011101100000000101010110100100011001001000111110111011010111011001000111101010010000111111000011110110010000010001011001001000011100001010101110101100101100111111010001000001110001010011001010101111101111100`

The first four bits of this string are `0011`, which is consistent with the output given by the Ian Coleman tool.


---

### Answer by username_2 on 2024-04-20. Score: 0

when I want "$ echo "11101000010011101010101000100110001100110000110011001011101100101111100001100110101000011101110000010101010111101001010010111010" | shasum -a 256 -b" convert python language to "sha256\_hash = hashlib.sha256(data.encode()).hexdigest()", it return "7529ea5a2f86b91b4b72e41aa36c190e8173e2fef6bbda828f74e55022eefec8", wrong result, BUT I don't know which error came from?


---

