SHA-256 banner

Interactive Bitcoin Cryptography Demo

Private Keys, Public Keys, and Address Generation

Enter any text, phrase, or random string. This input is used as a starting point to demonstrate how a Bitcoin private key is derived. Each tiny change in your input will produce a drastically different cryptographic result, showcasing the “avalanche effect”.

The input text is converted to bytes and passed through the SHA256 hash function. SHA256 produces a 256-bit (64 hexadecimal characters) cryptographic hash, which we treat as a private key for demonstration. In Bitcoin, private keys must be kept secret, as they control access to funds in corresponding addresses.
SHA256 (private key):
The private key is used in an elliptic curve multiplication on the secp256k1 curve to derive a public key. The compressed public key format begins with a `02` or `03` byte (reflecting parity of the y coordinate) followed by 32 bytes for the x coordinate. This format is standard in modern Bitcoin, saving space and fees.
Public Key (compressed):
The public key is hashed using SHA256. This intermediary step helps prepare it for address creation and contributes to Bitcoin’s strong security and irreversibility properties.
SHA256 (public key):
The SHA256 hash from the previous step is further passed into RIPEMD-160, resulting in a 20-byte public key hash. This double hashing provides additional security: it produces a shorter value for address use, and mitigates vulnerabilities of using a single hash function.
RIPEMD-160 (SHA256(pubkey)):
To create a Bitcoin address, a version byte (0x00 for standard addresses) is added to the front of the public key hash. This is hashed twice with SHA256 to create a 4-byte checksum, which is appended to the end. The complete result is encoded with Base58Check, producing a human-readable Bitcoin address—what you share to receive bitcoin.
Bitcoin Address (Base58Check):

Bitcoin addresses are derived from private keys, which are 256-bit numbers. This means there are up to 1 in 1.16 × 1077 possible private keys. The chance of randomly generating an address that matches one already used, or controls any funds, is so close to zero it's essentially impossible.

  1. Use the generated private key to construct a transaction spending funds from the matching Bitcoin address.
  2. The transaction is digitally signed with the private key, proving you own it.
  3. Broadcast the signed transaction to the Bitcoin network, where miners verify and add it to the blockchain.

SHA-256 FAQs

Find out what SHA-256 is and is it secure?

Q. What is SHA-256?

SHA-256 (Secure Hash Algorithm 256-bit) is a cryptographic hash function that produces a 256-bit (32-byte) fixed-length hash from any input data.

Q. Why is SHA-256 important in Bitcoin?

SHA-256 is used for mining (Proof of Work) and in the process of generating Bitcoin addresses and verifying transactions, providing security and integrity for the blockchain

Q. Is SHA-256 reversible - can I get the original data from the hash?

No. SHA-256 is designed to be one-way; it's practically impossible to reconstruct the original input from its hash.

Q. Can two different inputs have the same SHA-256 hash?

This is called a "collision," and while possible in theory, no practical collisions have been found due to SHA-256's design and 256-bit output size.

Q. How is SHA-256 different from SHA-1 or MD5?

SHA-256 offers a much longer output (256 bits) and much higher collision resistance than older hashes like SHA-1 (160 bits) or MD5 (128 bits), which are considered insecure now.

Q. What does the output of SHA-256 look like?

It's a 64-character hexadecimal string, e.g. cf80cd8aed482d5d1527d7dc72fceff84e6326592848447d2dc0b0e87dfc9a90

Q. What are common uses for SHA-256?

Bitcoin mining, digital signatures, message authentication codes, password hashing, file verification, and secure communications.

Q. Is SHA-256 secure and safe from quantum computers?

SHA-256 is very secure. Quantum computing may theoretically reduce the work needed to break SHA-256, but doubling the output size (e.g., SHA-512) is considered safe for the foreseeable future.

Q. How does SHA-256 handle different input sizes?

Regardless of input size (short or long), SHA-256 always produces a fixed-length 256-bit hash.

Q. Is SHA-256 used outside of Bitcoin?

Yes, SHA-256 is widely used in SSL/TLS, certificate signing, software distribution, and many security protocols.

Read more

RIPEMD-160 FAQs

FInd out mroe about RIPEMD-160 hash function

Q. What is RIPEMD-160?

RIPEMD-160 is a cryptographic hash function that outputs a 160-bit (20-byte) hash value, designed for secure hashing and digital fingerprinting of data.

Q. Why is RIPEMD-160 important in Bitcoin?

RIPEMD-160 is used together with SHA-256 to create Bitcoin addresses, increasing address security and compactness.

Q. What makes RIPEMD-160 unique?

Its dual-compression structure - two parallel lines of computation that provides extra cryptanalytic resistance over previous hash functions.

Q. Is RIPEMD-160 secure?

Yes, as of now, RIPEMD-160 is considered secure, with no known practical collision attacks. It’s more secure than MD5 and SHA-1.

Q. What does the RIPEMD-160 output look like?

It's a 40-character hexadecimal string (20 bytes), e.g. 62f6db8cec6c4af38bb5b45170c1d85084194d2e

Q. When should I use RIPEMD-160 vs SHA-256?

RIPEMD-160 is favored when a shorter hash is needed (e.g., addresses in Bitcoin) and for diversity in cryptographic designs, but SHA-256 is preferred for general security tasks.

Q. How is RIPEMD-160 used in blockchain technology?

Bitcoin addresses are generated by hashing a public key first with SHA-256, then RIPEMD-160, producing the "hash160" used as the address.

Q. Is RIPEMD-160 safe from quantum computers?

Quantum computers present future risks, but using RIPEMD-160 in conjunction with SHA-256 makes brute-force attacks much harder.

Q. Does RIPEMD-160 handle different input sizes?

Yes, like all hash functions, RIPEMD-160 takes any input size and always outputs a fixed 160-bit hash.

Q. Where else is RIPEMD-160 used?

It is used for digital signatures, checksums, authentication codes, and in cryptographic protocols outside of blockchain for its compact output and security.

Read more