<p><a href="https://bitcoin.stackexchange.com/a/19108/18196">This answer</a> provides a good description of a task similar to what you are trying to accomplish. </p>

<p><a href="https://en.bitcoin.it/wiki/Script" rel="nofollow noreferrer">This wiki page</a> shows how scripts are serialized and deserialized. It's actually not very hard to extract the raw opcodes from the script by hand, especially if you know it's a standard type of script.</p>

<p>But, you may use <a href="https://chainquery.com/bitcoin-api/decodescript" rel="nofollow noreferrer">https://chainquery.com/bitcoin-api/decodescript</a> and paste in the raw hex of the scriptSig for a more automated solution. The parsed opcodes will be in the <code>result.asm</code> field, including any raw data (such as signatures and pubkeys) separated by spaces. If you look for the element(s) of the script that start with 02/03/04, that will be the public key.</p>

CC BY-SA 3.0
2016-08-17T18:24:45.133Z
2016-08-17T19:23:53.820Z
2017-04-13T12:47:33.583Z
morsecoder
<p>You seem to be under the impression that addresses are generated from a scriptSig, which is wrong. Addresses are always generated off of the <code>scriptPubKey</code> in the output of a transaction. The <code>scriptSig</code> spends that <code>scriptPubKey</code>. Inside of the the <code>scriptPubKey</code>, there is a constant called a <code>pubkeyhash</code> which is what is used to generate a bitcoin adddress. This <code>pubkeyhash</code> will be different depending on if your <code>pubkey</code> is compressed or uncompressed. Here is an example of a console session using <a href="https://github.com/bitcoin-s/bitcoin-s-core" rel="nofollow">bitcoin-s</a> to demonstrate how compressed vs uncompressed public keys generate  different addresses </p>

<pre><code>chris@chris-870Z5E-880Z5E-680Z5E:~/dev/bitcoins-core$ sbt console 
[info] Loading project definition from /home/chris/dev/bitcoins-core/project
[info] Set current project to bitcoin-s-core (in build file:/home/chris/dev/bitcoins-core/)
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions to have them evaluated.
Type :help for more information.

scala&gt; import org.bitcoins.core.crypto._
import org.bitcoins.core.crypto._

scala&gt; import org.bitcoins.core.protocol._ 
import org.bitcoins.core.protocol._

scala&gt; val privKey = ECPrivateKey() 
privKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,true)

scala&gt; val pubKey = privKey.publicKey
pubKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(023e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6)

scala&gt; val unCompressedPrivKey = ECPrivateKey.fromHex(privKey.hex,false)
unCompressedPrivKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,false)

scala&gt; val unCompressedPublicKey = unCompressedPrivKey.publicKey
unCompressedPublicKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(043e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6e05500f2e535d80296db3c106ee9030a31c34c1723d5dbd64f39335f9d18e0aa)

scala&gt; import org.bitcoins.core.config._
import org.bitcoins.core.config._
//note these two hashes are different ! ! ! 
scala&gt; val pubKeyHash = CryptoUtil.sha256Hash160(pubKey.bytes)
pubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(a83f9e96392c2b9809cdc5e0ef3893b3877e575d)

scala&gt; val unCompressedPubKeyHash = CryptoUtil.sha256Hash160(unCompressedPublicKey.bytes)
unCompressedPubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(f1492e86f3daff5ed261e60980b9b494f6c13ff6)

scala&gt; val address = P2PKHAddress(pubKeyHash, MainNet) 
address: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1GLcjb1qbbspXEGBoGdm7aaU51KK4iKAa3)

scala&gt; val unCompressedAddress = P2PKHAddress(unCompressedPubKeyHash, MainNet) 
unCompressedAddress: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1NzoWzJkPWbNENd3XkJNYf1S9BxhLThb8M)
</code></pre>

<p>So if you were to provide the uncompressed version of the public key in the <code>scriptSig</code> instead of the compressed version (or vice versa if you hashed the uncompressed version with <code>OP_HASH160</code>) you will get an error saying the data was not equivalent. </p>

CC BY-SA 3.0
2016-08-18T13:02:46.753Z
2016-08-18T13:02:46.753Z
Chris Stewart
<p><a href="https://bitcoin.stackexchange.com/questions/38051/op-equalverify-non-equal-data">This</a> is the top ranking result on google for <code>OP_EQUALVERIFY: non-equal data</code> error.</p>

<p>In the answer, the person gets the uncompressed public key and its address from the scriptSig.</p>

<p>Is there a website link I can be pointed to where I can give scriptSig as input, and receive the uncompressed public key and address please?</p>

<script>
Debugging OP_EQUALVERIFY: non-equal data: how to get uncompressed public key and address from scriptSig
Peter PitLock
# Debugging OP_EQUALVERIFY: non-equal data: how to get uncompressed public key and address from scriptSig

(Asked by: username_0 on 2016-08-17)

[This](https://bitcoin.stackexchange.com/questions/38051/op-equalverify-non-equal-data) is the top ranking result on google for `OP_EQUALVERIFY: non-equal data` error.

In the answer, the person gets the uncompressed public key and its address from the scriptSig.

Is there a website link I can be pointed to where I can give scriptSig as input, and receive the uncompressed public key and address please?

**Tags:** script


---

## 2 answers

### Answer by username_1 on 2016-08-17. Score: 2 | Accepted answer

[This answer](https://bitcoin.stackexchange.com/a/19108/18196) provides a good description of a task similar to what you are trying to accomplish.

[This wiki page](https://en.bitcoin.it/wiki/Script) shows how scripts are serialized and deserialized. It's actually not very hard to extract the raw opcodes from the script by hand, especially if you know it's a standard type of script.

But, you may use <https://chainquery.com/bitcoin-api/decodescript> and paste in the raw hex of the scriptSig for a more automated solution. The parsed opcodes will be in the `result.asm` field, including any raw data (such as signatures and pubkeys) separated by spaces. If you look for the element(s) of the script that start with 02/03/04, that will be the public key.


---

### Answer by username_2 on 2016-08-18. Score: 2

You seem to be under the impression that addresses are generated from a scriptSig, which is wrong. Addresses are always generated off of the scriptPubKey in the output of a transaction. The scriptSig spends that scriptPubKey. Inside of the the scriptPubKey, there is a constant called a pubkeyhash which is what is used to generate a bitcoin adddress. This pubkeyhash will be different depending on if your pubkey is compressed or uncompressed. Here is an example of a console session using bitcoin-s to demonstrate how compressed vs uncompressed public keys generate  different addresses 
chris@chris-870Z5E-880Z5E-680Z5E:~/dev/bitcoins-core$ sbt console 
[info] Loading project definition from /home/chris/dev/bitcoins-core/project
[info] Set current project to bitcoin-s-core (in build file:/home/chris/dev/bitcoins-core/)
[info] Starting scala interpreter...
[info] 
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions to have them evaluated.
Type :help for more information.

scala> import org.bitcoins.core.crypto._
import org.bitcoins.core.crypto._

scala> import org.bitcoins.core.protocol._ 
import org.bitcoins.core.protocol._

scala> val privKey = ECPrivateKey() 
privKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,true)

scala> val pubKey = privKey.publicKey
pubKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(023e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6)

scala> val unCompressedPrivKey = ECPrivateKey.fromHex(privKey.hex,false)
unCompressedPrivKey: org.bitcoins.core.crypto.ECPrivateKey = ECPrivateKey(06e166f6d40cf6366bfa8f0b60f8f8526fde4095322af89ee9db64569f7db680,false)

scala> val unCompressedPublicKey = unCompressedPrivKey.publicKey
unCompressedPublicKey: org.bitcoins.core.crypto.ECPublicKey = ECPublicKey(043e5970f3fdf82372ca6778837caff638caf81bdee7a8ba70f16130a299b6c5d6e05500f2e535d80296db3c106ee9030a31c34c1723d5dbd64f39335f9d18e0aa)

scala> import org.bitcoins.core.config._
import org.bitcoins.core.config._
//note these two hashes are different ! ! ! 
scala> val pubKeyHash = CryptoUtil.sha256Hash160(pubKey.bytes)
pubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(a83f9e96392c2b9809cdc5e0ef3893b3877e575d)

scala> val unCompressedPubKeyHash = CryptoUtil.sha256Hash160(unCompressedPublicKey.bytes)
unCompressedPubKeyHash: org.bitcoins.core.crypto.Sha256Hash160Digest = Sha256Hash160DigestImpl(f1492e86f3daff5ed261e60980b9b494f6c13ff6)

scala> val address = P2PKHAddress(pubKeyHash, MainNet) 
address: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1GLcjb1qbbspXEGBoGdm7aaU51KK4iKAa3)

scala> val unCompressedAddress = P2PKHAddress(unCompressedPubKeyHash, MainNet) 
unCompressedAddress: org.bitcoins.core.protocol.P2PKHAddress = P2PKHAddressImpl(1NzoWzJkPWbNENd3XkJNYf1S9BxhLThb8M)

So if you were to provide the uncompressed version of the public key in the scriptSig instead of the compressed version (or vice versa if you hashed the uncompressed version with OP_HASH160) you will get an error saying the data was not equivalent.


---

