连续密钥密码 - 在线编码器和解码器工具
The Running Key cipher is a Vigenere variant that uses a long passage of text, such as a book excerpt, as the encryption key. Instead of repeating a short keyword, the key stretches across the entire message, eliminating the cyclic patterns that make standard Vigenere vulnerable to frequency analysis. Use this free tool to encrypt and decrypt Running Key cipher messages using any text passage as your key.
Settings
Frequently Asked Questions About Running Key Cipher
What is a running key cipher?
A running key cipher is a polyalphabetic substitution cipher that uses a long text passage (typically from a book) as its encryption key. Unlike the Vigenère cipher which uses a short repeating keyword, the running key cipher uses a key that is as long as the message, making it significantly harder to break through standard frequency analysis.
How does a running key cipher differ from a Vigenère cipher?
Both use a tabula recta for encryption, but they differ in key source. A Vigenère cipher uses a short keyword that repeats (e.g., 'SECRET'), while a running key cipher uses a long passage of text from a known source like a book. This means the running key never repeats within the message, eliminating the periodic patterns that Kasiski examination exploits.
Is a running key cipher the same as a book cipher?
No. A running key cipher uses book text as a key to encrypt each letter via the tabula recta, producing ciphertext letters. A book cipher uses the positions of words in a book (e.g., page-line-word numbers) to indicate plaintext words directly. The running key is a substitution cipher; the book cipher is a code system.
How do you break a running key cipher?
Running key ciphers are vulnerable to crib-dragging attacks. An analyst guesses a probable plaintext word, subtracts it from the ciphertext at every position, and checks if the resulting key text forms readable English. Since both the plaintext and key are natural language, valid decryptions produce English text in both streams simultaneously.
What makes a good running key?
A good running key should come from a widely available, specific text that both sender and receiver can access identically — such as a specific edition of a book, starting at an agreed page and line. The text should be prose (not poetry or lists) to avoid predictable patterns. Never reuse the same key passage for multiple messages.
Is the running key cipher secure?
The running key cipher offers moderate security but is not considered secure by modern standards. While it eliminates the periodic key repetition that weakens Vigenère, both the plaintext and key consist of natural language with predictable frequency distributions. Crib-dragging and statistical attacks can break it. For true security, use a one-time pad with truly random key material.
What is the relationship between running key cipher and one-time pad?
The one-time pad can be seen as a perfected running key cipher. If the running key text were truly random (not natural language), the system would be a one-time pad with mathematically proven unbreakability. The running key's vulnerability comes precisely from using predictable book text instead of random characters.
How to use the autokey cipher instead?
The autokey cipher is a related system where the plaintext itself becomes part of the key after an initial keyword. Try our Autokey Cipher tool at https://caesarcipher.org/ciphers/autokey for this variant. For the Vigenère cipher with a repeating keyword, use our Vigenère Cipher tool at https://caesarcipher.org/ciphers/vigenere.
Related Ciphers
You May Also Like
我们的流动密钥密码工具是一款免费在线流动密钥密码编码与解码器,以长篇书籍文本作为加密密钥。与使用重复密钥的传统密码不同,流动密钥密码多表替换方法采用整段书籍文字来创建安全消息。无论你是在学习古典密码学,还是需要一个实用的流动密钥密码书本加密工具,我们的平台都能提供即时的流动密钥密码加密服务,并配有可视化演示。
什么是流动密钥密码?
流动密钥密码是一种多表替换密码,它使用一段长文本——通常来自书籍、文件或其他已出版作品——作为加密密钥。明文的每个字母与密钥文本中对应的字母通过塔布拉・雷克塔(方阵密码表)(26×26 的移位字母网格)组合,生成密文字母。
流动密钥密码与标准维吉尼亚密码的核心区别在于密钥长度。维吉尼亚密码使用一个短关键词,循环重复覆盖整个消息;而流动密钥则使用一个至少与明文等长的密钥。这消除了周期性重复,从而使维吉尼亚密码容易受到 Kasiski 检验和重合指数分析攻击的弱点不再适用。
从历史上看,通信双方会事先约定一本特定的书籍、版本、页码和起始行。这个"指示符"使双方能够推导出相同的密钥文本,而无需传输密钥本身——只需传递书籍参考信息即可,通常被伪装在看似无害的通信中。
流动密钥密码代表了从简单多表系统向理论上无法破解的一次性密码本演进过程中的重要一步。如果流动密钥文本是真正随机的而非自然语言,该系统将实现完美保密。
如何使用流动密钥加密
流动密钥密码加密过程使用与维吉尼亚密码相同的数学公式:C[i] = (P[i] + K[i]) mod 26,其中 P 为明文字母,K 为密钥字母,C 为生成的密文字母。每个字母映射为一个数字(A=0,B=1,……Z=25)。
分步示例,以 Kernighan 和 Ritchie 合著的《C 程序设计语言》中的一段文字作为流动密钥:
- 明文: ATTACK AT DAWN
- 密钥文本: A TUTORIAL INTRODUCTION(取自第 1 章开头,仅保留字母:ATUTORIALINTRODUCTION)
- 处理过程(仅字母):
| 位置 | 明文 | 密钥 | 计算 | 密文 |
|---|---|---|---|---|
| 1 | A (0) | A (0) | (0+0) mod 26 = 0 | A |
| 2 | T (19) | T (19) | (19+19) mod 26 = 12 | M |
| 3 | T (19) | U (20) | (19+20) mod 26 = 13 | N |
| 4 | A (0) | T (19) | (0+19) mod 26 = 19 | T |
| 5 | C (2) | O (14) | (2+14) mod 26 = 16 | Q |
| 6 | K (10) | R (17) | (10+17) mod 26 = 1 | B |
| 7 | A (0) | I (8) | (0+8) mod 26 = 8 | I |
| 8 | T (19) | A (0) | (19+0) mod 26 = 19 | T |
| 9 | D (3) | L (11) | (3+11) mod 26 = 14 | O |
| 10 | A (0) | I (8) | (0+8) mod 26 = 8 | I |
| 11 | W (22) | N (13) | (22+13) mod 26 = 9 | J |
| 12 | N (13) | T (19) | (13+19) mod 26 = 6 | G |
- 结果: ATTACKATDAWN → AMNTQBITOIJG
密钥文本的长度必须至少与明文相同。如果在加密前将两段文本中的空格和标点符号都去除,则只有字母字符参与计算。
如何解密
解密是加密公式的逆运算:P[i] = (C[i] - K[i] + 26) mod 26。接收方必须拥有与加密时完全相同的密钥文本。
以上述示例为例:
- 密文: AMNTQBITOIJG
- 密钥文本: ATUTORIALINTRODUCTION
- 第一个字母: A (0) - A (0) + 26 = 26,mod 26 = 0 → A
- 第二个字母: M (12) - T (19) + 26 = 19,mod 26 = 19 → T
- 对每个字母重复此过程,即可还原:ATTACKATDAWN
发送方和接收方必须就如何从原始文本中提取密钥字符达成一致——是否包含空格、标点,以及如何处理大小写。密钥提取方式的任何不一致都会导致明文乱码。
流动密钥 vs 维吉尼亚 vs 自动密钥密码
流动密钥密码属于一组多表替换密码家族,它们都使用塔布拉・雷克塔(方阵密码表),但生成密钥流的方式各不相同。
| 特性 | 流动密钥 | 维吉尼亚 | 自动密钥密码 |
|---|---|---|---|
| 密钥来源 | 书籍段落或长文本 | 简短易记的关键词 | 初始关键词 + 明文 |
| 密钥长度 | 至少与消息等长 | 较短,循环重复 | 随消息增长 |
| 密钥重复 | 从不重复 | 每 N 个字母重复一次 | 不重复 |
| Kasiski 攻击 | 不适用 | 高度有效 | 不适用 |
| 已知明文拖拽攻击 | 主要攻击方式 | 不需要 | 可行但更难 |
| 密钥分发 | 约定书籍 + 位置 | 共享单个单词 | 共享初始关键词 |
| 安全级别 | 中等 | 低 | 中等 |
| 历史用途 | 军事情报 | 外交通信 | 应用有限 |
维吉尼亚密码最为简单:短关键词(如"SECRET")重复延伸以匹配消息长度。自动密钥密码通过在初始关键词后附加明文本身来改进这一点,使密钥不再重复。流动密钥密码则采用完全不同的方法,以外部文本作为密钥来源。
流动密钥密码 vs 书本密码
尽管在日常对话中有时被互换使用,流动密钥密码和书本密码在本质上是完全不同的系统:
-
流动密钥密码:一种替换密码,使用书籍文本作为密钥,通过塔布拉・雷克塔(方阵密码表)对每个明文字母进行变换。输出为字母(或表示字母的数字)。密钥文本与明文进行数学运算。
-
书本密码:一种编码系统,使用书中单词的位置来表示明文单词。输出由指示页码、行号和单词位置的数字组成(例如,"42-7-3"表示第 42 页、第 7 行、第 3 个单词)。不进行数学变换——书籍被用作密码本。
流动密钥密码逐字母加密,而书本密码以整个单词为单位操作。破解流动密钥需要密码分析;破解书本密码需要找到正确的书籍。
安全性分析
流动密钥密码处于易被破解的维吉尼亚密码与理论上无法破解的一次性密码本之间的中间地带。
已知明文拖拽攻击:流动密钥密码的主要弱点在于明文和密钥都由自然语言构成。攻击者猜测一个可能的明文单词("已知明文"),在每个位置将其从密文中减去,然后检查得到的密钥文本是否构成可读的英语。由于英语文本具有独特的统计特性,有效的明文猜测会产生可识别的密钥文本——反之亦然。这种攻击方法由威廉·弗里德曼在 20 世纪初正式提出。
与一次性密码本的关联:如果流动密钥是真正的随机字符而非书籍文本,该密码将变成具有数学证明的完美保密性的一次性密码本。流动密钥的弱点来自自然语言的统计可预测性——常见字母频率、双字母组合模式和单词结构都留下了随机密钥不会留下的可检测痕迹。
实际防御措施:历史上的使用者通过选择晦涩的文本(技术手册、行业期刊、年鉴)而非著名文学作品来提高安全性,在不可预测的位置开始密钥,并且从不复用同一密钥段落。部分使用者还在流动密钥输出的基础上附加了额外的加密层。
历史
流动密钥密码的概念从早期多表系统演化而来。**塔布拉・雷克塔(方阵密码表)**本身由 Johannes Trithemius 于 1508 年描述,Blaise de Vigenère 于 1586 年对该概念进行了扩展。然而,将长段文本系统性地用作流动密钥是后来才发展出来的。
法国数学家 Arthur Joseph Hermann 于 1892 年描述了流动密钥方法,正式确立了将书籍文本用作非重复多表密钥的做法。该方法在 19 世纪末至 20 世纪初得到了军事和外交通信的实际应用。
威廉·弗里德曼,常被称为美国密码分析学之父,在 20 世纪 20 年代开发了攻击流动密钥密码的系统方法。他基于已知明文(词条)分析和高频双字母统计的技术证明,自然语言密钥提供的安全性远低于其长度所暗示的水平。弗里德曼的工作直接为一次性密码本的理论基础做出了贡献,Claude Shannon 后来于 1949 年从数学上证明了一次性密码本的不可破解性。
在二战和冷战期间,流动密钥密码在军事上的应用有限,因为更安全的系统(包括一次性密码本和机械密码机)已经可用。然而,流动密钥密码在情报人员中仍然流行,因为它可以手工完成而无需携带可疑设备——只需一本随手可得的书即可。
相关密码工具
探索这些相关的多表替换密码和古典密码工具: