> For the complete documentation index, see [llms.txt](https://www.0x1.academy/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.0x1.academy/gei-kai-fa-zhe-de-zhi-nan/cryptography/hash.md).

# 哈希算法

> **最後更新：2026 年 1 月**

## 給我任何東西，我還你一串編號

哈希函數(Hash Function或Hash)又稱雜湊函數，是一個密碼學[黑箱](https://en.wikipedia.org/wiki/Black_box)，可以接受任何的數位輸入，基本上是任何東西：抖音影像檔，江山美人mp3檔，你的生日日期，只要輸入進去，就會得到一串固定長度的獨一無二的編號，又稱哈希值。

## 不可回推性

酷的地方在於，任何一個哈希值的輸出都無法回推原本的輸入內容。比方說輸入"小熊維尼"可以得到"0x878787"，我們卻沒有任何方式由單純的"0x878787"回推成"小熊維尼"。

## 夠亂

第二個酷的地方在於，輸入的值若有一些些的改變，儘管再細微，都會讓最後輸出的哈希值截然不同。比方說原本輸入"Obama"可以得到"0x342389"，只要將"Obama"改為"Omama"，輸出將會變成完全不同的值例如"0x850184"，之類的。

## 以下是實際運算"Obama"vs. "Omama"的[sha256](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha256.md)值

於terminal執行以下，可以得出"Obama"的sha256值

```bash
echo -n "Obama" | shasum -a 256
```

結果為

```bash
c7d2c7996caf51c565d31fef43b08c1e48f7230e14fd17c4234fa1e9b7d0dabd
```

我們試將"Obama"改為"Omama"

```bash
echo -n "Omama" | shasum -a 256
```

結果為

```
a02d0d7a388ba8e1ddc0b5804667fceb4a6ec355464d98d2fff7c6c3c527759d
```

**可以發現它們完全不一樣！**

***

#### 相關條目

* [SHA256](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha256.md)
* [SHA3](/gei-kai-fa-zhe-de-zhi-nan/cryptography/sha3.md)

#### 參考資料
