import hashlib
header_hex = ("01000000" + "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" + "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" + "c7f5d74d" + "f2b9441a" + "42a14695")
header_bin = header_hex.decode('hex')
test = hashlib.sha256(header_bin).digest()
print "Pervyi prokhod"
print test
hash = hashlib.sha256(hashlib.sha256(header_bin).digest()).digest()
test1 = hash.encode('hex_codec')
print "Itog"
print '1dbd981fe6985776b644b173a4d0385ddc1aa2a829688d1e0000000000000000'
print "Raschet"
print test1
hash[::-1].encode('hex_codec')
aW1wb3J0IGhhc2hsaWIKaGVhZGVyX2hleCA9ICgiMDEwMDAwMDAiICsgIjgxY2QwMmFiN2U1NjllOGJjZDkzMTdlMmZlOTlmMmRlNDRkNDlhYjJiODg1MWJhNGEzMDgwMDAwMDAwMDAwMDAiICsgImUzMjBiNmMyZmZmYzhkNzUwNDIzZGI4YjFlYjk0MmFlNzEwZTk1MWVkNzk3ZjdhZmZjODg5MmIwZjFmYzEyMmIiICsgImM3ZjVkNzRkIiArICJmMmI5NDQxYSIgKyAiNDJhMTQ2OTUiKQpoZWFkZXJfYmluID0gaGVhZGVyX2hleC5kZWNvZGUoJ2hleCcpCnRlc3QgPSBoYXNobGliLnNoYTI1NihoZWFkZXJfYmluKS5kaWdlc3QoKQpwcmludCAiUGVydnlpIHByb2tob2QiCnByaW50IHRlc3QKaGFzaCA9IGhhc2hsaWIuc2hhMjU2KGhhc2hsaWIuc2hhMjU2KGhlYWRlcl9iaW4pLmRpZ2VzdCgpKS5kaWdlc3QoKQp0ZXN0MSA9IGhhc2guZW5jb2RlKCdoZXhfY29kZWMnKQpwcmludCAiSXRvZyIKcHJpbnQgJzFkYmQ5ODFmZTY5ODU3NzZiNjQ0YjE3M2E0ZDAzODVkZGMxYWEyYTgyOTY4OGQxZTAwMDAwMDAwMDAwMDAwMDAnCnByaW50ICJSYXNjaGV0IgpwcmludCB0ZXN0MQpoYXNoWzo6LTFdLmVuY29kZSgnaGV4X2NvZGVjJyk=
aW1wb3J0IGhhc2hsaWIKaGVhZGVyX2hleCA9ICgmcXVvdDswMTAwMDAwMCZxdW90OyArICZxdW90OzgxY2QwMmFiN2U1NjllOGJjZDkzMTdlMmZlOTlmMmRlNDRkNDlhYjJiODg1MWJhNGEzMDgwMDAwMDAwMDAwMDAmcXVvdDsgKyAmcXVvdDtlMzIwYjZjMmZmZmM4ZDc1MDQyM2RiOGIxZWI5NDJhZTcxMGU5NTFlZDc5N2Y3YWZmYzg4OTJiMGYxZmMxMjJiJnF1b3Q7ICsgJnF1b3Q7YzdmNWQ3NGQmcXVvdDsgKyAmcXVvdDtmMmI5NDQxYSZxdW90OyArICZxdW90OzQyYTE0Njk1JnF1b3Q7KQpoZWFkZXJfYmluID0gaGVhZGVyX2hleC5kZWNvZGUoJ2hleCcpCnRlc3QgPSBoYXNobGliLnNoYTI1NihoZWFkZXJfYmluKS5kaWdlc3QoKQpwcmludCAmcXVvdDtQZXJ2eWkgcHJva2hvZCZxdW90OwpwcmludCB0ZXN0
import hashlib
header_hex = ("01000000" + "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" + "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" + "c7f5d74d" + "f2b9441a" + "42a14695")
header_bin = header_hex.decode('hex')
test = hashlib.sha256(header_bin).digest()
print "Pervyi prokhod"
print test