恩尼格玛密码机示例和教程

通过涵盖转子机制、双步进异常、插板配置和二战历史消息的逐步示例了解恩尼格玛密码机的工作原理。

Step-by-Step: Encrypting the Letter "A"

Using the default configuration (Rotors I-II-III, Reflector UKW-B, positions A-A-A, no plugboard):

1
Step Rotors:The right rotor advances one position (A→B) before the signal enters.
2
Plugboard (Input):Letter A passes through the plugboard. With no pairs set, A remains A.
3
Right Rotor (Forward):The signal enters rotor III from the right side, following the wiring from contact A through the scrambled alphabet.
4
Middle Rotor (Forward):The signal continues through rotor II, getting further scrambled.
5
Left Rotor (Forward):The signal passes through rotor I, the third and final rotor.
6
Reflector:The reflector (UKW-B) bounces the signal back through the rotors via a different path. Crucially, no letter maps to itself.
7
Rotors (Reverse):The signal travels back through all three rotors in reverse order (I → II → III), using the inverse wiring at each stage.
8
Plugboard (Output):The signal passes through the plugboard one final time.
9
Output:The lamp lights up showing the encrypted letter B. The letter A can never encrypt to itself.

Input: A → Output: B

Verify this yourself: with default settings, typing AAAA produces BDZG.

The Double-Stepping Anomaly

The most fascinating mechanical quirk of the Enigma machine. When the middle rotor reaches its notch position, it steps again on the very next keypress — stepping twice in succession. This "double stepping" was a mechanical artifact that reduced the theoretical period of the machine.

Frequently Asked Questions

How does rotor stepping work in the Enigma machine?

The right rotor steps before every keypress. The middle rotor steps when the right rotor reaches its notch position. The left rotor steps when the middle rotor reaches its notch position. This creates the double-stepping anomaly where the middle rotor can advance on two consecutive keypresses.

What is the double-stepping anomaly?

Double stepping occurs when the middle rotor is at its notch position. The mechanical pawl engages and causes the middle rotor to step again when the left rotor advances, making it move on two consecutive keypresses instead of one. This slightly reduces the cipher's period.

Why can't a letter encrypt to itself on the Enigma?

The reflector pairs up all 26 letters and sends the signal back through the rotors. Since the reflector connects each letter to a different letter, the signal always returns as a different letter. This property was exploited by Alan Turing's Bombe machine to eliminate impossible configurations.

What were cribs in Enigma codebreaking?

Cribs were known or guessed plaintext segments. Codebreakers at Bletchley Park knew that German messages often contained predictable phrases like 'WETTERBERICHT' (weather report) or 'KEINEBESONDERENEREIGNISSE' (nothing special to report). These cribs were used to test possible Enigma settings.

恩尼格玛密码机示例——逐步学习

通过涵盖转子机制、插接板配置和历史消息的全面分步示例,掌握恩尼格玛密码机。这些示例从基本概念逐步深入到真实的二战操作规程。所有示例均可使用我们的恩尼格玛密码机模拟器进行验证。

示例 1:无插接板的基础加密

这个基础示例演示恩尼格玛如何通过转子组件加密单个字母,不使用任何插接板连接。

配置

  • 转子:I、II、III(从左到右)
  • 位置:A、A、A
  • 环设置:1、1、1(默认)
  • 反射器:UKW-B
  • 插接板:无连接

加密"A"

第一步: 按任意键前,右侧转子(III)从 A 步进到 B。

第二步: "A"的信号经过以下路径:

  • 入口轮:A(位置 0)
  • 右侧转子(III 位于位置 B):通过转子 III 连线进行替换
  • 中间转子(II 位于位置 A):通过转子 II 连线进行替换
  • 左侧转子(I 位于位置 A):通过转子 I 连线进行替换
  • 反射器 UKW-B:配对字母并反射信号
  • 左侧转子(I)反向:逆向替换
  • 中间转子(II)反向:逆向替换
  • 右侧转子(III)反向:逆向替换
  • 输出灯亮起

关键点: 由于右侧转子在加密前步进,第一个字母以 AAB 位置(而非 AAA)加密。这对于重现历史结果非常重要。

示例 2:互反特性

恩尼格玛的反射器确保加密和解密是同一种操作。本示例演示这一关键特性。

配置

  • 转子:II、IV、V
  • 位置:B、L、A
  • 环设置:2、21、12
  • 反射器:UKW-B
  • 插接板:AV、BS、CG、DL、FU、HZ、IN、KM、OW、RX

演示

  1. 用上述设置加密"HELLO"。结果:一个 5 字母密文(在模拟器中试试)。
  2. 将转子位置重置回 B、L、A。
  3. 输入第 1 步的密文。输出结果为"HELLO"。

这一互反特性既是一个优点(操作员只需一套操作规程),也是一个漏洞(它限制了密码的数学结构)。

示例 3:双重步进实例

当中间转子处于其缺口位置时,会发生双重步进异常,导致它在连续两次按键中都步进。

配置

  • 转子:I、II、III
  • 反射器:UKW-B
  • 插接板:无

观察双重步进的设置

将位置设为 A、D、U(左、中、右)。转子 III 的缺口在 V,转子 II 的缺口在 E。

观察按键时的转子位置变化:

按键次数步进前位置步进后位置备注
第 1 次A, D, UA, D, V右侧转子正常步进
第 2 次A, D, VA, E, W右侧转子到达缺口(V),中间转子也步进
第 3 次A, E, WB, F, X中间转子到达缺口(E),双重步进!中间和左侧同时步进
第 4 次B, F, XB, F, Y恢复正常步进

第 3 次按键的双重步进是异常所在:中间转子在连续两次按键(第 2 次和第 3 次)中都步进。这缩短了机器的理论周期。

示例 4:历史背景——巴巴罗萨行动

在德国入侵苏联期间(巴巴罗萨行动,1941 年 6 月),恩尼格玛加密消息协调了大规模三路进攻。以下是一条典型军事消息的结构示例:

典型消息格式

德国军队恩尼格玛消息遵循严格格式:

  1. 消息密钥:操作员选择三个随机字母,用当天的设置加密后在消息开头发送
  2. 消息正文:实际内容,用消息密钥加密
  3. 标准短语:消息通常以可预测的短语开头,破译者将其作为"已知词"加以利用

布莱切利庄园使用的常见已知词

  • WETTERBERICHT("天气报告")— 定时发送的天气消息
  • KEINEBESONDERENEREIGNISSE("无特别事项报告")— 例行状态消息
  • ANXX("致"后接收件人)— 消息地址格式
  • OBERKOMMANDODERWEHRMACHT — 最高统帅部署名

这些可预测的模式对于炸弹机器缩小每日设置的可能范围至关重要。

示例 5:预设配置

模拟器包含几种预设配置,演示不同的操作场景:

默认国防军配置

常用转子选择和插接板对的标准军用起始点。这代表了密码本中分发的典型每日设置。

潜艇配置

德国海军(Kriegsmarine)使用了更复杂的变体,配备额外转子。海军恩尼格玛尤为重要,因为破解它帮助盟军赢得了大西洋海战。

非洲军团配置

隆美尔部队在北非使用的野战配置。沙漠作战需要跨越广阔距离进行可靠通信。

在模拟器中尝试每种预设,观察不同配置如何从相同明文产生完全不同的密文。