# 凯撒密码

凯撒密码是一种替换密码，其中消息的每个字母都被替换为字母表中向后固定位数的字母，从Z绕回A。它也被称为移位密码，得名于尤利乌斯·凯撒（Julius Caesar），据传他以三位移位将其用于机密通信。<sup>[1](https://emc2.byu.edu/math495R/Lab05_CaesarCipher/03_caesar.html)</sup><sup> • </sup><sup>[2](https://lexundria.com/suet_jul/56.6/r)</sup>

| 关键事实 | 详情 |
|---|---|
| 操作方式 | 每个明文字母循环向前移动固定的密钥 \( k \) 位；当 \( k = 1 \) 时，HELLO 变为 IFMMP<sup>[1](https://emc2.byu.edu/math495R/Lab05_CaesarCipher/03_caesar.html)</sup> |
| 公式 | 加密为 \( C = (P + k) \bmod 26 \)；解密使用 \( -k \bmod 26 \)<sup>[3](https://cs.bc.edu/~straubin/crypto-2014/Lecture2.pdf)</sup> |
| 历史移位 | 苏维托尼乌斯（Suetonius）记载，凯撒在私人信件中以D代替A，即三位移位<sup>[2](https://lexundria.com/suet_jul/56.6/r)</sup> |
| 密钥空间 | 仅有25个非平凡密钥（算上恒等映射为26个），因此逐一尝试所有密钥直到出现可读文本即可破译<sup>[4](https://caesarcipher.org/learn/brute-force-attack-caesar-cipher)</sup> |
| 密码分析 | 字母频率分析可从足够长的消息中恢复密钥；已知一个加密字符即可解密全文<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln04.html)</sup><sup> • </sup><sup>[6](https://www.southampton.ac.uk/~wright/1001/chapter-morecryptography.html)</sup> |
| 现代地位 | 不适用于真正的加密；其主要用途是教授加密基础知识和日常混淆，如ROT13<sup>[7](https://caesarcipher.org/ciphers/compare)</sup> |

## 工作原理

该密码作用于字母A到Z。每个字母向前移动 \( k \) 位，Z绕回A；当 \( k = 1 \) 时，A变为B，B变为C，Z变为A，因此HELLO WORLD加密为IFMMP XPSME。当 \( k = 2 \) 时，同一明文变为JGNNQ YQTNF。一般而言，每个字母可移动 \( n \) 位，其中 \( n \in \mathbb{Z} \)。<sup>[1](https://emc2.byu.edu/math495R/Lab05_CaesarCipher/03_caesar.html)</sup>

将字母写为数字，A = 0，B = 1，直至Z = 25，则用密钥 \( k \) 加密明文字母 \( p \) 为 \( C = (P + k) \bmod 26 \)，解密时以 \( -k \bmod 26 \) 代替 \( k \)。<sup>[3](https://cs.bc.edu/~straubin/crypto-2014/Lecture2.pdf)</sup><sup> • </sup><sup>[8](https://cs50.harvard.edu/extension/2026/spring/psets/2/caesar/)</sup> 解密只是撤销移位：既然加密将每个字母向前移动了 \( n \) 位，解密便将每个字母向后移动相同的位数。<sup>[1](https://emc2.byu.edu/math495R/Lab05_CaesarCipher/03_caesar.html)</sup> 非字母字符通常原样保留。<sup>[8](https://cs50.harvard.edu/extension/2026/spring/psets/2/caesar/)</sup>

## 古代文献

凯撒本人并未在其存世著作中讨论过该密码或其可能的名称。对该密码的描述——同样未提及其名称——见于苏维托尼乌斯、奥卢斯·格利乌斯（Aulus Gellius）和卡西乌斯·狄奥（Cassius Dio）的著作中，而“凯撒密码”一词仅出现在现代密码学书籍中。<sup>[9](https://research-information.bris.ac.uk/ws/portalfiles/portal/263833703/Myths_and_Histories_of_the_Spartan_scytale_29_11_2020.pdf)</sup>

**苏维托尼乌斯的记述。** 在其《尤利乌斯·凯撒传》（56.6）中，苏维托尼乌斯写道，在致亲信的私人事务信件中，若凯撒有机密之事要说，他便用密码书写，“如此改变字母表的字母顺序，以至于无法辨认出任何词语”，而试图解密者“必须以字母表第四个字母，即D，代替A，其余依此类推”。<sup>[2](https://lexundria.com/suet_jul/56.6/r)</sup> 卡西乌斯·狄奥写道，凯撒的秘密信件对大多数人而言不可理解，但并非所有人；他描述其以第四个字母代替正确字母的做法，以使文字对多数人不可理解。<sup>[9](https://research-information.bris.ac.uk/ws/portalfiles/portal/263833703/Myths_and_Histories_of_the_Spartan_scytale_29_11_2020.pdf)</sup>

该密码并非凯撒唯一的隐藏技术。在其《高卢战记》（*Commentarii de Bello Gallico*）中，他描述了向西塞罗发送一封加密消息，其中明文的拉丁字母被希腊字母所替换。<sup>[10](https://perpustakaan.atmaluhur.ac.id/uploaded_files/temporary/DigitalCollection/NjEwZDIyM2EwNjMwMjQzMjgxZWUwM2MxY2ZhNTJiOGU0NzIyNDA0YQ%3D%3D.pdf)</sup>

## 破解密码

**暴力破解。** 该密码的根本弱点在于其密钥空间很小：仅有25个可能的非平凡密钥。攻击者无需专门的数学知识，也无需计算机，只需耐心尝试每一个密钥，直到明文出现。<sup>[4](https://caesarcipher.org/learn/brute-force-attack-caesar-cipher)</sup> 对于英语消息，这在实践中行之有效，因为通常除正确解密外，所有解密结果都立即显现为乱码。<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln04.html)</sup>

**频率分析。** 该密码是一种单表替换，即每个字母的每次出现总是被替换为同一个字母，因此明文中最频繁出现的字母对应密文中最频繁出现的字母。给定足够长的已知语言消息，分析者可以将最常见的密文字母与该语言的频率分布（英语中为E、T、A、O、I、N等）对齐，密钥便自然得出，无论名义密钥数量如何。<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln04.html)</sup><sup> • </sup><sup>[11](https://web.cecs.pdx.edu/~dmcgrath/courses/F26/introsec/history-of-cryptography.html)</sup> 已知最早的密码分析文本是9世纪博学家金迪（al-Kindī）的《论破译密码信息》（*Risālah fī Istikhrāj al-Muʿammā*），约公元850年写于巴格达，描述的正是这种方法，这也是已知最早的任何形式的统计推断应用。<sup>[11](https://web.cecs.pdx.edu/~dmcgrath/courses/F26/introsec/history-of-cryptography.html)</sup><sup> • </sup><sup>[12](https://sites.wcsu.edu/mbxml/html/section_arab_analysis.html)</sup>

结构上的弱点是单个字符的加密值决定了整个密钥。对于凯撒密码，知道一个字符的加密值即可解密全文；与其最接近的推广形式——仿射密码则需要两个。<sup>[6](https://www.southampton.ac.uk/~wright/1001/chapter-morecryptography.html)</sup>

## 与其他古典密码的关系

凯撒密码仅使用了字母表26!种可能排列中的26种旋转。一般单表替换密码使用全部排列，密钥空间大于 \( 2^{74} \)，对暴力破解而言过大，但给定足够长的消息，此类密码仍易被频率分析破解。<sup>[5](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln04.html)</sup>

**仿射密码。** 仿射凯撒密码将移位推广为 \( x \mapsto ax + b \pmod{p} \)，即先将每个字母的数值乘以密钥 \( a \)，再加上 \( b \)。

**ROT13。** ROT13，即13位移位，是凯撒密码的一个特例，其特殊性质在于加密和解密是同一操作，因为13是26的一半。

## 现代用途

凯撒密码作为教学工具存续至今：它是密码学入门中的标准第一例，是哈佛CS50问题集等编程练习的主题，并且在简单古典密码中，最适合用于教授替换基础知识和秘密参数的概念。<sup>[7](https://caesarcipher.org/ciphers/compare)</sup><sup> • </sup><sup>[8](https://cs50.harvard.edu/extension/2026/spring/psets/2/caesar/)</sup><sup> • </sup><sup>[15](https://www.usna.edu/Users/cs/wcbrown/courses/si110AY13S/lec/l24/lec.html)</sup>

## References

1. [Caesar (Shift) Cipher, BYU Math 495R](https://emc2.byu.edu/math495R/Lab05_CaesarCipher/03_caesar.html)
2. [Suetonius, The Life of Julius Caesar 56.6, translated by J. C. Rolfe](https://lexundria.com/suet_jul/56.6/r)
3. [CSCI3381 Cryptography, Lecture 2, Boston College](https://cs.bc.edu/~straubin/crypto-2014/Lecture2.pdf)
4. [Brute Force Attack on Caesar Cipher, CaesarCipher.org](https://caesarcipher.org/learn/brute-force-attack-caesar-cipher)
5. [Lecture notes 4: Cryptanalysis of the Caesar Cipher, Yale University CS467](https://zoo.cs.yale.edu/classes/cs467/2006f/attach/ln04.html)
6. [Chapter 9: More cryptography, MATH1001 Introduction to Number Theory, University of Southampton](https://www.southampton.ac.uk/~wright/1001/chapter-morecryptography.html)
7. [Cipher Comparison Table, CaesarCipher.org](https://caesarcipher.org/ciphers/compare)
8. [Caesar, CS50, Harvard Extension School](https://cs50.harvard.edu/extension/2026/spring/psets/2/caesar/)
9. [Myths and Histories of the Spartan scytale, University of Bristol research repository](https://research-information.bris.ac.uk/ws/portalfiles/portal/263833703/Myths_and_Histories_of_the_Spartan_scytale_29_11_2020.pdf)
10. [Secret Writing in Ancient Civilization](https://perpustakaan.atmaluhur.ac.id/uploaded_files/temporary/DigitalCollection/NjEwZDIyM2EwNjMwMjQzMjgxZWUwM2MxY2ZhNTJiOGU0NzIyNDA0YQ%3D%3D.pdf)
11. [A History of Cryptography, Portland State University](https://web.cecs.pdx.edu/~dmcgrath/courses/F26/introsec/history-of-cryptography.html)
12. [Arabic Analysis of the Alphabet, Western Connecticut State University](https://sites.wcsu.edu/mbxml/html/section_arab_analysis.html)
13. [Affine enciphering, Stony Brook University](https://www.math.stonybrook.edu/~scott/papers/Book331/Affine_enciphering.html)
14. [Block Cipher Techniques, NIST CSRC](https://csrc.nist.gov/Projects/block-cipher-techniques)
15. [SI110: Symmetric Encryption, United States Naval Academy](https://www.usna.edu/Users/cs/wcbrown/courses/si110AY13S/lec/l24/lec.html)

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

Topic: 物质世界与数学 › 数学与统计学 › 逻辑与离散数学 › General discrete mathematics and discrete structures › Discrete mathematics

Copyright 2026 Edgepedia

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

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

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