Cryptography – Post 1: Hashing Basics

Cryptography – Post 1: Hashing Basics

I’ve recently started diving into cryptography — not from the headlines, but from the ground up.
I’m starting with hashing: what it is, how it works, and where it shows up in real systems.

What is Hashing?

Hashing is the process of turning any piece of data (text, password, file, etc.) into a fixed-length, irreversible string — called a hash or digest.

A good hash function has these properties:

  • Deterministic → same input = same output
  • One-way → you can’t go backwards
  • Collision-resistant → different inputs = different outputs
  • Fixed-size output → regardless of input length

Hashing vs. Encryption

FeatureHashingEncryption
DirectionOne-way (irreversible)Two-way (encrypt & decrypt)
Output lengthFixedVariable
Main purposeVerify, compare, fingerprintHide content from unauthorized access
ExamplesPassword storage, checksumsSecuring messages, files, etc.

Basic Hashing in Python (SHA-256)

import hashlib

msg = "hello world"
hashed = hashlib.sha256(msg.encode()).hexdigest()
print(hashed)

Output:

nginxKopierenBearbeitenb94d27b9934d3e08a52e52d7da7dabfac484efe37a5380ee9088f7ace2efcde9

Even changing 1 character would give a completely different hash.

Where Is Hashing Used?

  1. Password storage
    Instead of saving the password directly, you save only the hash of it.
    When the user logs in, hash their input and compare the result.
  2. File integrity checks
    Sites often share SHA256 hashes of files.
    If your download has a different hash, it’s been tampered with.
  3. Digital signatures
    Hashing ensures the data being signed is authentic and unchanged.
  4. Blockchain
    Each block stores a hash of the previous block, linking the chain.

Not All Hash Functions Are Equal

FunctionLengthStatus
MD5128-bitBroken (collisions found)
SHA-1160-bitBroken
SHA-256256-bitStrong (used in Bitcoin)
SHA-512512-bitStrong, longer

Older functions like md5 or sha1 are not secure for passwords or sensitive data anymore.

Why Use Salt?

Even though hashing is irreversible, there’s still a risk:

If two people use the same password, their hashes will be identical — which helps attackers.

Solution: Add a unique salt (random string) to each password before hashing.

password = "password123"
salt = "a8#r@9k*"
combined = password + salt
hashed = hashlib.sha256(combined.encode()).hexdigest()

Now even if two users have the same password, their hashes will differ.

Summary

  • Hashing is NOT encryption — it’s a one-way transformation.
  • It’s everywhere: login systems, downloads, blockchains.
  • Strong algorithms like SHA-256 are essential.
  • Salting is required for secure password hashing.
  • Hashing is often the first step before doing more advanced cryptography like digital signatures or encryption.

Leave a Reply

Your email address will not be published. Required fields are marked *