Photo AI

Last Updated Sep 27, 2025

Hashing Simplified Revision Notes

Revision notes with simplified explanations to understand Hashing quickly and effectively.

user avatar
user avatar
user avatar
user avatar
user avatar

243+ students studying

Hashing

Overview

Hashing is a process that converts data into a fixed-size string of characters, typically using a mathematical algorithm known as a hash function. The output, called a hash value or hash code, is unique to the original data. Hashing is commonly used for data storage, data retrieval, and ensuring data integrity. It is particularly useful for securely storing sensitive information, such as passwords.

Purpose and Need for Hashing

  1. Data Integrity: Hashing helps verify that data has not been altered, as even a tiny change in the original data produces a completely different hash. This makes it useful for detecting data corruption or tampering.
  2. Efficient Data Retrieval: In databases, hashing enables fast data access by assigning unique hash values to data entries. This allows direct access to data without needing to search through all entries.
  3. Security for Sensitive Data: Hashing protects sensitive information, such as passwords, by storing only the hash of the data rather than the data itself. Even if an attacker gains access to the hash, they cannot retrieve the original data directly.

How Hashing Works

  1. Hash Function: A hash function takes an input (like a password or document) and returns a fixed-length hash value. Common hash functions include MD5 (Message Digest Algorithm 5), SHA-1 (Secure Hash Algorithm 1), and SHA-256 (Secure Hash Algorithm 256).
  2. Deterministic Output: The same input always produces the same hash output, ensuring consistency for data retrieval and comparison.
  3. Fixed Length: Regardless of the input size, hash values have a fixed length (e.g., 256 bits for SHA-256), making them ideal for efficient storage and indexing.

Properties of Hashing

  • Uniqueness: Ideally, each unique input produces a unique hash value. Although not guaranteed, a good hash function minimises the probability of two different inputs producing the same hash (a collision).
  • Irreversibility: Hash functions are one-way functions, meaning it's computationally infeasible to derive the original data from the hash value alone. This property is crucial for storing sensitive information like passwords.
  • Speed: Hash functions are designed to process data quickly, making them efficient for large datasets and rapid lookups.

Uses of Hashing

Storing Passwords Securely

  • Purpose: Rather than storing plain text passwords, systems store the hash of the password. When a user enters their password, the system hashes it and compares the result to the stored hash. This ensures that even if the hash database is compromised, the original passwords remain secure.
  • Password Verification Process:
    1. User enters a password.
    2. The system hashes the entered password.
    3. The resulting hash is compared with the stored hash. If they match, the password is correct.
lightbulbExample

Example: A user's password, "MySecret123", is hashed to produce a hash value such as b2f5ff47436671b6e533d8dc3614845d.

The hash value, not the actual password, is stored in the system.

Data Retrieval in Hash Tables

Purpose: Hash tables use hashing to store and retrieve data quickly by associating each data item with a unique hash. This provides constant time complexity, making it highly efficient for large datasets.

lightbulbExample

Example: A hash table for storing student IDs might use the student's name as input, generating a hash value that determines the storage location of the student's record.

When the student's name is entered, the hash is recalculated, allowing the system to quickly retrieve the associated record.

Data Integrity Verification

Purpose: Hashing verifies that files or messages haven't been altered, ensuring data integrity. A hash of the original data is created and compared to a recalculated hash when the data is received.

lightbulbExample

Example: When a file is downloaded, a hash value provided by the source can be recalculated and compared with the hash of the downloaded file.

If the hashes match, the file is unaltered; if they don't, it indicates potential corruption or tampering.

Common Hash Functions

MD5 (Message Digest Algorithm 5)

  • Produces a 128-bit hash.
  • Generally used for basic checksums but is now considered weak due to vulnerabilities that allow hash collisions (where two different inputs produce the same hash).

SHA-1 (Secure Hash Algorithm 1)

  • Produces a 160-bit hash.
  • Previously popular, but like MD5, it is now considered insecure for sensitive data due to collision vulnerabilities.

SHA-256 (Secure Hash Algorithm 256)

  • Part of the SHA-2 family, producing a 256-bit hash.
  • Currently one of the most secure and widely used hashing algorithms, especially for applications needing strong data integrity and security.

Example of Hashing in Python

infoNote

Below is an example of hashing a password using Python's hashlib library and the SHA-256 algorithm.

import hashlib

def hash_password(password):
    # Encode the password and hash it using SHA-256
    hash_object = hashlib.sha256(password.encode())
    hashed_password = hash_object.hexdigest()
    return hashed_password

# Example usage
password = "MySecurePassword123"
hashed = hash_password(password)
print("Original Password:", password)
print("Hashed Password:", hashed)

Explanation of the Example

  • Encoding: The password is encoded to a byte format compatible with the hash function.
  • Hashing: The SHA-256 algorithm hashes the password.
  • Result: The hashed password is stored as a hexadecimal string, which is much shorter and more secure to store than the original password.

Benefits and Drawbacks of Hashing

Benefits:

  • Data Security: Hashing provides a secure way to store sensitive information by transforming it into a fixed-length value that cannot easily be reversed.
  • Efficient Data Retrieval: Hash tables use hashing to enable fast and efficient data lookup, which is ideal for large databases.
  • Data Integrity: Hashing ensures data integrity by verifying that data has not been altered, as any changes will produce a different hash.

Drawbacks:

  • Collisions: Although rare, different inputs can occasionally produce the same hash value, resulting in a collision. Stronger hashing algorithms like SHA-256 minimise this risk.
  • Irreversibility: Hashing is a one-way function, meaning the original data cannot be retrieved from the hash. This is beneficial for security but limits its use in situations where data needs to be recovered.
  • Vulnerability to Brute Force Attacks: Simple hashing without additional security measures (like salting) is vulnerable to brute force or dictionary attacks.

Note Summary

infoNote

Key Takeaways

  • Hashing is a process that converts data into a fixed-size hash value using a hash function, making it essential for data integrity and security.
  • Uses of Hashing: Commonly used for secure password storage, quick data retrieval in hash tables, and data integrity verification.
  • Hash Functions: Popular algorithms include MD5, SHA-1, and SHA-256, with SHA-256 being the preferred choice for security-sensitive applications.
  • Hashing is irreversible, making it secure for storing sensitive data, although additional measures like salting are often used to enhance security for applications such as password storage.
Books

Only available for registered users.

Sign up now to view the full note, or log in if you already have an account!

500K+ Students Use These Powerful Tools to Master Hashing

Enhance your understanding with flashcards, quizzes, and exams—designed to help you grasp key concepts, reinforce learning, and master any topic with confidence!

40 flashcards

Flashcards on Hashing

Revise key concepts with interactive flashcards.

Try Computer Science Flashcards

4 quizzes

Quizzes on Hashing

Test your knowledge with fun and engaging quizzes.

Try Computer Science Quizzes

29 questions

Exam questions on Hashing

Boost your confidence with real exam questions.

Try Computer Science Questions

27 exams created

Exam Builder on Hashing

Create custom exams across topics for better practice!

Try Computer Science exam builder

12 papers

Past Papers on Hashing

Practice past papers to reinforce exam experience.

Try Computer Science Past Papers

Other Revision Notes related to Hashing you should explore

Discover More Revision Notes Related to Hashing to Deepen Your Understanding and Improve Your Mastery

96%

114 rated

Compression, Encryption & Hashing

Lossy & Lossless Compression

user avatar
user avatar
user avatar
user avatar
user avatar

342+ studying

185KViews

96%

114 rated

Compression, Encryption & Hashing

Run Length Encoding & Dictionary Coding

user avatar
user avatar
user avatar
user avatar
user avatar

308+ studying

193KViews

96%

114 rated

Compression, Encryption & Hashing

Symmetric vs Asymmetric Encryption

user avatar
user avatar
user avatar
user avatar
user avatar

433+ studying

190KViews
Load more notes

Join 500,000+ A-Level students using SimpleStudy...

Join Thousands of A-Level Students Using SimpleStudy to Learn Smarter, Stay Organized, and Boost Their Grades with Confidence!

97% of Students

Report Improved Results

98% of Students

Recommend to friends

500,000+

Students Supported

50 Million+

Questions answered