> For the complete documentation index, see [llms.txt](https://alham-rizvi.gitbook.io/alhamrizvi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/02.-intro-to-hashing.md).

# Introduction to Hashing

## What is Hashing

Hashing is the process of converting input data of any size into a fixed-size output using a mathematical function.

```
h = H(m)
```

* `m` = message (input)
* `H` = hash function
* `h` = hash (output)

The output is also called a **digest**.

## Simple Example

```python
import hashlib

m = b"hello"

h = hashlib.md5(m).hexdigest()
print(h)
```

Output:

```
5d41402abc4b2a76b9719d911017c592
```

The same input will always produce the same hash.

## Why Hashing is Used

Hashing is widely used in cryptography and systems:

* Password storage (store hash, not password)
* Data integrity (verify file hasn’t changed)
* Digital signatures
* Blockchain
* Caching and indexing

## Key Idea

Hashing is **not encryption**.

Encryption:

```
reversible (you can decrypt)
```

Hashing:

```
one-way (you cannot reverse it)
```

## Important Characteristics

A good cryptographic hash function has:

### 1. Deterministic

Same input → same output

### 2. Fixed Length

No matter input size, output size is constant

Example:

```
MD5 → 128 bits
SHA256 → 256 bits
```

### 3. Fast Computation

Efficient to compute

### 4. One-Way Function

Given hash, you cannot get original input

### 5. Avalanche Effect

Small change in input → completely different hash

## Example of Avalanche Effect

```
Input 1: hello
Input 2: hello1
```

Hashes:

```
5d41402abc4b2a76b9719d911017c592
203ad5ffa1d7c650ad681fdff3965cd2
```

A tiny change → completely different output.

## Common Hash Functions

* MD5 (broken, but common in CTFs)
* SHA-1 (broken)
* SHA-256 (secure)
* SHA-512 (secure)
* SHA-3 (modern)

## Important Clarification

You do NOT "decrypt" hashes.

Instead:

```
You guess the input and compare hashes
```

## Mental Model

Think of hashing like a machine:

```
Input → Black Box → Fixed Output
```

You can go forward easily, but not backward.

## Summary

* Hashing converts data into fixed-size output
* It is one-way and irreversible
* Used for security, integrity, and verification
* Core concept for almost all cryptographic systems


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://alham-rizvi.gitbook.io/alhamrizvi/cryptography/hashing/02.-intro-to-hashing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
