<p>If the output of SHA256 is hex, you must convert hex to bytes before passing that to RIPEMD160.</p>

<p>See <a href="http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript" rel="nofollow">http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript</a></p>

<pre><code> var hash160 = Crypto.RIPEMD160(Crypto.util.hexToBytes(Crypto.SHA256(publicKeyBytes)))
</code></pre>

CC BY-SA 3.0
2014-06-08T09:28:10.707Z
Thank you for answer. However, I still have problem with getting proper value.
me.ex
CC BY-SA 3.0
2014-06-08T10:44:38.743Z
Oh, I made mistake in implementation :) It works great! Thank you!
me.ex
CC BY-SA 3.0
2014-07-17T21:31:03.740Z
@me.ex please click "approve" next to the answer, and upvote it. That way hsmiths will get karma :)
kolinko
CC BY-SA 3.0
2014-06-06T23:46:28.097Z
2014-06-06T23:56:27.400Z
2014-06-06T23:56:27.400Z
hsmiths
<p>I am trying to implement JavaScript interpreter for Bitcoin scripts, but I have problem with counting value of OP_HASH160. I found that</p>

<p>Hash160(x) = RIPEMD160(SHA256(x))</p>

<p>However, when I try to count it this way using CryptoJS library, I get different value than on page <a href="http://paulkernfeld.com/bse/" rel="nofollow">http://paulkernfeld.com/bse/</a>.</p>

<p><code>CryptoJS.RIPEMD160(CryptoJS.SHA256(<strong>"02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"</strong>)).toString() = "e81794c3da1564a196665dd0f74483185f524fe2"
</code></p>

<p>where <strong>"02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"</strong> is the first element on the top of the stack.</p>

<p>Could somebody explain how exactly operation OP_HASH160 works?</p>

<p>Thx! :)</p>

<script>
Problem with value after OP_HASH160
me.ex
# Problem with value after OP_HASH160

(Asked by: username_0 on 2014-06-06)

I am trying to implement JavaScript interpreter for Bitcoin scripts, but I have problem with counting value of OP\_HASH160. I found that

Hash160(x) = RIPEMD160(SHA256(x))

However, when I try to count it this way using CryptoJS library, I get different value than on page <http://paulkernfeld.com/bse/>.

`CryptoJS.RIPEMD160(CryptoJS.SHA256("02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f")).toString() = "e81794c3da1564a196665dd0f74483185f524fe2"`

where **"02c34538fc933799d972f55752d318c0328ca2bacccd5c7482119ea9da2df70a2f"** is the first element on the top of the stack.

Could somebody explain how exactly operation OP\_HASH160 works?

Thx! :)

**Tags:** script


---

## 1 answers

### Answer by username_1 on 2014-06-06. Score: 1

If the output of SHA256 is hex, you must convert hex to bytes before passing that to RIPEMD160.

See <http://procbits.com/2013/08/27/generating-a-bitcoin-address-with-javascript>

```
 var hash160 = Crypto.RIPEMD160(Crypto.util.hexToBytes(Crypto.SHA256(publicKeyBytes)))

```

> **Comments:**
> **username_0**: Thank you for answer. However, I still have problem with getting proper value.  
> **username_0**: Oh, I made mistake in implementation :) It works great! Thank you!  
> **username_2**: @username_0 please click "approve" next to the answer, and upvote it. That way username_1 will get karma :)  

---

