Search code examples
pythonbitcoinsha256sha

SHA256 doesn't yield same result


I'm following on this tutorial and in part 2 (picture below) it shows that the SHA256 yields a result different than what I get when I ran my python code:

the string is: 0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6

While the tutorial SHA256 comes to: 600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408

My short python shows:

sha_result = sha256(bitconin_addresss).hexdigest().upper()
print sha_result

32511E82D56DCEA68EB774094E25BAB0F8BDD9BC1ECA1CEEDA38C7A43ACEDDCE

in fact, any online sha256 shows the same python result; so am I missing here something?

enter image description here


Solution

  • You're hashing the string when you're supposed to be hashing the bytes represented by that string.

    >>> hashlib.sha256('0450863AD64A87AE8A2FE83C1AF1A8403CB53F53E486D8511DAD8A04887E5B23522CD470243453A299FA9E77237716103ABC11A1DF38855ED6F2EE187E9C582BA6'.decode('hex')).hexdigest().upper()
    '600FFE422B4E00731A59557A5CCA46CC183944191006324A447BDB2D98D4B408'