# 希尔密码

希尔密码是一种经典的对称多表代换密码，它将明文分成若干字母块，把每块写成一个数字向量，再乘以一个秘密的密钥矩阵并对字母表大小（通常为26）取模，从而完成加密。亨特学院的莱斯特·S·希尔（Lester S. Hill）在1929年6-7月《美国数学月刊》第36卷第306-312页发表的论文《代数字母表中的密码学》中提出了这一方法，并在1931年的第二篇论文中作了扩展。<sup>[1](https://sites.math.washington.edu/~king/coursedir/m308a01/Projects/Cryptography.htm)</sup> 这是将线性代数应用于多表代换密码的第一个通用方法；尽管以现代标准看它并不安全，但至今仍是密码学和线性代数课程中的标准示例。<sup>[2](https://www.apprendre-en-ligne.net/crypto/hill/HillICTCM12.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 发明 | 莱斯特·S·希尔，《代数字母表中的密码学》，《美国数学月刊》36卷（1929年6-7月），第306-312页；1931年发表第二篇论文<sup>[1](https://sites.math.washington.edu/~king/coursedir/m308a01/Projects/Cryptography.htm)</sup> |
| 加密规则 | 对于m×m密钥矩阵K和由m个字母组成的明文块，C = K P mod 26；解密为P = K⁻¹ C mod 26<sup>[3](https://www.munotes.in/notes/BSc-Computer-Science/TY-BSc-Computer-Science/Semester-5/Cyber-and-Information-Security/the-hill-cipher/)</sup> |
| 密钥有效条件 | 密钥必须在模26下可逆，即要求gcd(det K, 26) = 1<sup>[4](https://math.asu.edu/sites/default/files/hill.pdf)</sup> |
| 密钥空间 | 分组长度为2时约有45,000个有效密钥，分组长度为3时约有52,000,000,000个<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup> |
| 主要弱点 | 拥有n对已知明密文块的已知明文攻击只需一次矩阵求逆即可恢复密钥<sup>[6](https://sinapsi.wiki/w/ctf-crypto/p/block-cipher/hill-cipher/)</sup> |
| 唯密文攻击 | 哈扎伊和艾哈迈迪（2017）将Z₂₆上d×d密钥的唯密文攻击复杂度从O(d³·26^(d²))降至O(d·13^d)<sup>[7](https://www.sciencedirect.com/science/article/pii/S0020019016301338)</sup> |
| 实际地位 | 不被认为对敏感应用足够安全；主要用于教学<sup>[4](https://math.asu.edu/sites/default/files/hill.pdf)</sup> |

## 加密的工作原理

首先将字母转换为数字，A = 0到Z = 25。明文被分成n个字母一组，每组视为一个列向量。加密时将密钥矩阵K乘以每个向量并对26取模；所得数字再转回字母。对于2×2密钥，一对字母(x, y)对应的密文字母为(ax + by) mod 26和(cx + dy) mod 26，其中a、b、c、d为密钥元素。<sup>[8](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)</sup> 例如，以密钥矩阵\( \begin{bmatrix} 5 & 11 \\ 1 & 22 \end{bmatrix} \)为例，字母块“NU”对应向量(13, 20)，加密后得到(285, 453)，对26取模后为(25, 11)，即字母“ZL”。<sup>[9](https://mathcenter.oxford.emory.edu/site/math125/hillCipher/)</sup>

解密时使用逆矩阵。由于运算是在模26下进行的，逆矩阵存在的条件是K的行列式在模26下有乘法逆元，即gcd(det K, 26) = 1；行列式为偶数、13的倍数或零时都无法解密。<sup>[4](https://math.asu.edu/sites/default/files/hill.pdf)</sup> 对于2×2密钥，逆矩阵由行列式ad − bc的乘法逆元和伴随矩阵元素构成；在一个计算示例中，a = 2、b = 3、c = 5、d = 6，行列式为−3 ≡ 23 (mod 26)，其逆元为17，解密矩阵的元素为A = 24、B = 1、C = 19、D = 8。<sup>[8](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)</sup> 如果消息长度不是分组长度的整数倍，则用X或Z等额外字母进行填充。<sup>[8](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)</sup>

分组长度等于密钥矩阵的维数：3×3密钥使用九个数字，加密三个字母一组，该方案可扩展到六个或更多字母一组。<sup>[8](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)</sup> 某些实现使用29个字符的字母表，增加一个空格和两个标点符号，使随机选取的矩阵更可能可逆。<sup>[10](https://dummit.cos.northeastern.edu/docs/cryptography_1_classical_cryptosystems.pdf)</sup>

## 该密码的效能

由于加密作用于整个字母块，希尔密码掩盖了单字母频率。明文中重复的双字母组和重复字母不会产生重复的密文模式；在一个例子中，“Mississippi”中重复的双字母组IS和SS以及重复字母S和P都被隐藏了。<sup>[11](https://www.cs.uri.edu/cryptography/classical-ciphers/hill/article.html)</sup> 改变一两个明文字母就可能完全改变对应的密文块，这使得仅靠频率分析难以破解该密码。<sup>[2](https://www.apprendre-en-ligne.net/crypto/hill/HillICTCM12.pdf)</sup> 普通频率分析的有效性随着分组长度的增加而迅速降低，而六个或更多字母一组的希尔密码并不难实现。<sup>[8](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)</sup>

有效密钥的数量随分组长度迅速增长：分组长度为2时约45,000个，分组长度为3时约52,000,000,000个，因此暴力搜索变得困难。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup>

## 密码分析

**已知明文攻击。** 该密码的根本弱点在于其线性性质。如果攻击者知道n对明文/密文块，且这些明文块在模26下线性无关，则方程C = K P构成一个可解的线性方程组，一次矩阵求逆即可恢复整个密钥。<sup>[6](https://sinapsi.wiki/w/ctf-crypto/p/block-cipher/hill-cipher/)</sup> 对于2×2密钥，两对已知双字母组给出四个关于四个未知密钥元素的模26线性同余方程，可直接求解。<sup>[12](https://websites.nku.edu/~christensen/1402%20Hill%20cipher.pdf)</sup> 程式化的消息开头和结尾往往能提供所需的已知明文，对于分组长度为2的情况，攻击几乎和合法解密一样容易。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup> 因此，希尔密码不被认为对敏感应用足够安全。<sup>[4](https://math.asu.edu/sites/default/files/hill.pdf)</sup> 现代分组密码总是包含非线性组件，正是为了防止这类攻击。<sup>[13](https://secgroup.dais.unive.it/teaching/cryptography/known-plaintext-attacks/)</sup>

**唯密文攻击。** 长期以来人们认为希尔密码能够抵抗唯密文攻击，这一说法在多本现代密码学教科书中被反复提及。沙赫拉姆·哈扎伊和西亚瓦什·艾哈迈迪于2017年在《信息处理快报》（第118卷，第25-29页）发表的论文推翻了这一看法：他们利用分治技术和中国剩余定理，利用字母频率在模2和模13下的非均匀性，将针对英语文本的Z₂₆上d×d希尔密码的攻击复杂度从O(d³·26^(d²))降至O(d·13^d)。<sup>[7](https://www.sciencedirect.com/science/article/pii/S0020019016301338)</sup>

## 历史与机械实现

希尔发表了两篇描述该系统的论文：1929年的《代数字母表中的密码学》和1931年3月《美国数学月刊》第38卷第135-154页的《论密码学中的某些线性变换装置》。<sup>[1](https://sites.math.washington.edu/~king/coursedir/m308a01/Projects/Cryptography.htm)</sup> 1931年的工作引入了扩展，其中最重要的现在被称为仿射希尔密码，它在矩阵乘积上加上一个常数向量，使密文方程形如C₁ ≡ k₁P₁ + k₂P₂ + m₁ (mod 26)；加性常数可以是任意值，只要行列式k₁k₄ − k₂k₃与26互素，密钥就仍然有效。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup>

为了回应该系统对日常使用过于复杂的质疑，希尔制造了一台密码机，使用一系列齿轮对六个字母一组进行加密，使其基本上无法通过频率分析破解；但这台机器从未流行起来。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup> 希尔和路易斯·魏斯纳（Louis Weisner）于1929年2月14日为这台“消息保护器”提交了专利申请，美国专利1,845,947于1932年2月16日颁发；该装置用齿状驱动轮和应答轮计算一系列数字关于某个模的线性函数，旨在用于标记银行支票和其他消息。<sup>[14](https://patents.google.com/patent/US1845947A/en)</sup>

希尔密码从未被大量使用，因为手工操作过于笨重，而机械密码学转而沿着多表代换转子机的方向发展。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup> 希尔从1927年起在亨特学院教授数学，直到1960年退休，他严谨的数学方法帮助密码学奠定了数学基础。<sup>[15](https://mrajacse.wordpress.com/wp-content/uploads/2012/01/an-introduction-to-cryptography.pdf)</sup>

## 遗产与变体

希尔密码对已知明文攻击的脆弱性使其在实践中无法使用，但它在密码学和线性代数中仍具有教学价值，许多大学密码学课程将其与DES和AES一起讲授，作为第一个分组密码和矩阵密码分析的练习。<sup>[16](https://arxiv.org/abs/1002.3567)</sup><sup>[17](https://www.radford.edu/registrar/course-descriptions/math/math-311.html)</sup> 大量提出的变体试图弥补这一弱点：用由最大距离可分（MDS）主密钥导出的可变长度密钥加密每个明文矩阵，<sup>[18](https://arxiv.org/abs/1210.1940)</sup> 从随机向量空间基生成动态可逆密钥矩阵，<sup>[19](https://arxiv.org/abs/1909.06781)</sup> 以及在单向哈希构造中使用GF(2)上的不可逆矩阵。<sup>[20](https://arxiv.org/abs/1210.1925)</sup> 希尔用线性方程组加密的核心思想随着数字计算机的出现重新变得重要，它构成了许多现代密码的组成部分，这些密码将此类线性层与非线性组件相结合。<sup>[5](https://assets.press.princeton.edu/chapters/s10826.pdf)</sup>

## References

1. [Paal Schiefloe, "Cryptography: Hill ciphers," University of Washington linear algebra project (2001)](https://sites.math.washington.edu/~king/coursedir/m308a01/Projects/Cryptography.htm)
2. [Murray Eisenberg, "Hill Ciphers: A Linear Algebra Project with Mathematica," University of Massachusetts Amherst](https://www.apprendre-en-ligne.net/crypto/hill/HillICTCM12.pdf)
3. ["The Hill Cipher," B.Sc. Computer Science notes, munotes](https://www.munotes.in/notes/BSc-Computer-Science/TY-BSc-Computer-Science/Semester-5/Cyber-and-Information-Security/the-hill-cipher/)
4. ["Hill Ciphers," School of Mathematical and Statistical Sciences, Arizona State University](https://math.asu.edu/sites/default/files/hill.pdf)
5. [Holden, *The Mathematics of Secrets*, chapter 1, Princeton University Press](https://assets.press.princeton.edu/chapters/s10826.pdf)
6. ["Hill Cipher — known-plaintext breaks it in one matrix inversion," Sinapsi wiki](https://sinapsi.wiki/w/ctf-crypto/p/block-cipher/hill-cipher/)
7. [Khazaei, S., and Ahmadi, S., "Ciphertext-only attack on d x d Hill in O(d·13^d)," *Information Processing Letters* 118 (2017), pp. 25-29](https://www.sciencedirect.com/science/article/pii/S0020019016301338)
8. [Scott Sutherland, "The Hill Cipher," Stony Brook Mathematics](https://www.math.stonybrook.edu/~scott/papers/MSTP/crypto/8Hill_Cipher.html)
9. ["The Hill Cipher," Emory University Math Center](https://mathcenter.oxford.emory.edu/site/math125/hillCipher/)
10. ["1.4.4 The Hill Cipher," cryptography course notes, Northeastern University](https://dummit.cos.northeastern.edu/docs/cryptography_1_classical_cryptosystems.pdf)
11. ["Hill Cipher," University of Rhode Island, Cryptography course](https://www.cs.uri.edu/cryptography/classical-ciphers/hill/article.html)
12. ["Section Seventeen: Hill cipher," Northern Kentucky University, Christensen](https://websites.nku.edu/~christensen/1402%20Hill%20cipher.pdf)
13. ["Known-plaintext attacks," Secgroup, Ca' Foscari University of Venice](https://secgroup.dais.unive.it/teaching/cryptography/known-plaintext-attacks/)
14. [US Patent 1,845,947, "Message Protector," Weisner and Hill, issued February 16, 1932](https://patents.google.com/patent/US1845947A/en)
15. [Bauer, *An Introduction to Cryptography*, second edition, chapter on classical ciphers](https://mrajacse.wordpress.com/wp-content/uploads/2012/01/an-introduction-to-cryptography.pdf)
16. ["A Secure Variant of the Hill Cipher," arXiv:1002.3567](https://arxiv.org/abs/1002.3567)
17. [MATH 311 course description, Radford University](https://www.radford.edu/registrar/course-descriptions/math/math-311.html)
18. ["Variable-length Hill Cipher with MDS Key Matrix," arXiv:1210.1940](https://arxiv.org/abs/1210.1940)
19. ["A Vector Space Approach to Generate Dynamic Keys for Hill Cipher," arXiv:1909.06781](https://arxiv.org/abs/1909.06781)
20. ["A Class of Non Invertible Matrices in GF(2) for Practical One Way Hash Algorithm," arXiv:1210.1925](https://arxiv.org/abs/1210.1925)

---
*Initially written Sep 17, 2026 · Reviewed: Sep 30, 2026; Oct 15, 2026 · Edited: Oct 15, 2026 · Last review: Oct 15, 2026*

Topic: 物质世界与数学 › 数学与统计学 › 数与代数 › Computational and symbolic algebra › Symbolic and algebraic algorithms › Applications of symbolic and algebraic algorithms

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/hill-cipher

English original: https://www.edgepedia.org/hill-cipher
