Created
March 6, 2018 18:23
-
-
Save vadim-su/fe58fc18467262642ef0394e53e098e3 to your computer and use it in GitHub Desktop.
Block hashing algorithm for python3 (https://en.bitcoin.it/wiki/Block_hashing_algorithm)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import hashlib | |
| from hashlib import sha256 | |
| import codecs | |
| def dsha256(data): | |
| return sha256(sha256(data).digest()).digest() | |
| def ripemd(data): | |
| return hashlib.new('ripemd160', data).digest() | |
| def main(): | |
| header_hex = ( | |
| "01000000" + | |
| "81cd02ab7e569e8bcd9317e2fe99f2de44d49ab2b8851ba4a308000000000000" + | |
| "e320b6c2fffc8d750423db8b1eb942ae710e951ed797f7affc8892b0f1fc122b" + | |
| "c7f5d74d" + "f2b9441a" + "42a14695" | |
| ) | |
| header_bin = codecs.decode(header_hex, 'hex') | |
| hash = dsha256(header_bin) | |
| print(hash.hex()) | |
| print(hash[::-1].hex()) | |
| if __name__ == '__main__': | |
| main() |
vadim-su
commented
Mar 6, 2018
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment