Posts

Write the python script to implement the hashes used for bitcoin-SHA 256

Bane Sons

 import hashlib


def sha256(data: bytes) -> bytes:

    """Single SHA-256 hash (returns raw bytes)"""

    return hashlib.sha256(data).digest()


def double_sha256(data: bytes) -> str:

    """Bitcoin-style Double SHA-256 hash (returns hex string)"""

    return hashlib.sha256(

        hashlib.sha256(data).digest()

    ).hexdigest()


# Example input (like a Bitcoin block header or transaction)

data = b"This is example Bitcoin data"


# Apply single SHA-256

single_hash = hashlib.sha256(data).hexdigest()

print("Single SHA-256 Hash:")

print(single_hash)


# Apply double SHA-256

double_hash = double_sha256(data)

print("\nDouble SHA-256 Hash (Bitcoin-style):")

print(double_hash)

Post a Comment