Python Double hash SHA256

0 votes

I am trying to double hash an input. 

The following function doublehashes input(it works for step 14 in this example)

def function(input):
    data = input.decode('hex_codec')
    result = binascii.hexlify(hashlib.sha256(hashlib.sha256(data).digest()).digest())
    print result

I have the following data.

given hash = 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000

The results are

string: "ae253ca2a54debcac7ecf414f6734f48c56421a08bb59182ff9f39a6fffdb588"

hex: "61 65 32 35 33 63 61 32 61 35 34 64 65 62 63 61 63 37 65 63 66 34 31 34 66 36 37 33 34 66 34 38 63 35 36 34 32 31 61 30 38 62 62 35 39 31 38 32 66 66 39 66 33 39 61 36 66 66 66 64 62 35 38 38 0d 0a"

Can someone help me?

Aug 29, 2018 in Blockchain by digger
• 26,740 points
1,927 views

1 answer to this question.

0 votes

You can get the given hash by reversing the genesis (bytes):

>>> import binascii                                                                             
>>> genesis = '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
>>> given_hash = '6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000'
>>> binascii.unhexlify(given_hash) == binascii.unhexlify(genesis)[::-1]
True
answered Aug 29, 2018 by slayer
• 29,370 points

Related Questions In Blockchain

0 votes
1 answer

How to compute SHA256 hash for bitcoin header

header_hex = "02000000aaf8ab82362344f49083ee4edef795362cf135293564c4070000000000000000c009bb6222e9bc4cdb8f26b2e8a2f8d163509691a4038fa692abf9a474c9b21476800755c02e17181fe6c1c3" # Decode header hex into ...READ MORE

answered Aug 31, 2018 in Blockchain by digger
• 26,740 points
1,482 views
0 votes
1 answer

SHA256 Hash doesn't match the one listed on Bitcoin Wiki

The problem occurring here is that you ...READ MORE

answered Feb 28, 2022 in Blockchain by Soham
• 9,710 points
774 views
+1 vote
1 answer

Security Properties of Hash Functions

The difference is indeed subtle. I understood ...READ MORE

answered Mar 27, 2018 in Blockchain by Johnathon
• 9,090 points
4,458 views
+1 vote
1 answer

Can a data be altered in a blockchain without changing its hash?

Yes, it should work. The authentication practice ...READ MORE

answered Apr 8, 2018 in Blockchain by Shashank
• 10,400 points
895 views
0 votes
1 answer

Python request module for bitcoin json rpc

This should work: #!/usr/bin/env python import getpass import json import requests ...READ MORE

answered Aug 28, 2018 in Blockchain by digger
• 26,740 points
2,363 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,923 views
+1 vote
3 answers

Removing double quotes from a string from JSON response in PHP

Just remove the json_encode call, and it should work: $resp ...READ MORE

answered Sep 12, 2018 in Blockchain by digger
• 26,740 points
45,219 views
+1 vote
1 answer
0 votes
1 answer

Passing hash string with smart contracts

eth.sendTransaction is a go etherum function. There more ...READ MORE

answered Jul 5, 2018 in Blockchain by slayer
• 29,370 points
1,453 views
+2 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP