Cryptography Essentials

Hash Functions

Hash Functions

Module 1 of Cryptography


What Is a Hash Function?

A hash function takes any input and produces a fixed-size output (the "hash" or "digest").

Input (any size)  →  Hash Function  →  Output (fixed size)

"Hello"           →     SHA-256     →  "185f8db32271fe25f561a6fc938b2e26..."
"Hello World"     →     SHA-256     →  "a591a6d40bf420404a011733cfb7b190..."
War and Peace     →     SHA-256     →  "2c5d36be542f8f0e2ff4e801e9749966..."

No matter if input is 5 characters or 5 million, output is always the same size.


Properties of Cryptographic Hash Functions

1. Deterministic

Same input always produces same output.

2. One-Way (Pre-image Resistance)

Given a hash, you can't figure out the input.

3. Avalanche Effect

Tiny input change → completely different output.

4. Collision Resistance

Practically impossible to find two different inputs with the same hash.


Why These Properties Matter for Blockchain

  • One-Way: Proof of Work mining
  • Deterministic: Anyone can verify work instantly
  • Avalanche Effect: Tamper evidence
  • Collision Resistance: Unique identifiers

Common Hash Functions

FunctionOutput SizeUsed By
SHA-256256 bitsBitcoin
Keccak-256256 bitsEthereum
RIPEMD-160160 bitsBitcoin addresses

Key Takeaways

  1. Hash functions compress arbitrary input to fixed output
  2. Cryptographic hashes are one-way, deterministic, with avalanche effect
  3. Blockchain uses hashes everywhere: block IDs, transaction IDs, addresses, mining