坦克精灵 / enigma
恩尼格玛引擎
v1.3
2021-08-03 22:49 UTC
Requires
- php: ^7.3
Requires (Dev)
- codeception/codeception: ^4.1
- codeception/module-asserts: ^1.0.0
- codeception/module-phpbrowser: ^1.0.0
README
恩尼格玛
安装
使用 Composer 安装
composer require tankfairies/enigma
详细信息
此包提供了三种不同恩尼格玛型号的功能
- 国防军/空军 3转子模型
- 海军 3转子模型
- 海军 4转子模型
每个模型都可以配备不同的转子组和反射器。总共有10种类型的转子和4种类型的反射器。
- 国防军/空军 3转子模型使用
- 转子:I, II, III, IV, V
- 反射器:B, C
- 海军 3转子模型使用
- 转子:I, II, III, IV, V, VI, VII, VIII
- 反射器:B, C
- 海军 4转子模型使用
- 转子:I, II, III, IV, V, VI, VII, VIII, Beta, Gamma
- 反射器:B Thin, C Thin
每个转子和反射器都提供独特的接线,不能更改。设置如下
- 接触点 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
- I = EKMFLGDQVZNTOWYHXUSPAIBRCJ
- II = AJDKSIRUXBLHWTMCQGZNPYFVOE
- III = BDFHJLCPRTXVZNYEIWGAKMUSQO
- IV = ESOVPZJAYQUIRHXLNFTGKDCMWB
- V = VZBRGITYUPSDNHLXAWMJQOFECK
- VI = JPGVOUMFYQBENHZRDKASXLICTW
- VII = NZJHGRCXMYSWBOUFAIVLPEKQDT
- VIII = FKQHTLXOCBJSPDZRAMEWNIUYGV
- Beta = LEYJVCNIXWPBQMDRTAKZGFUHOS
- Gamma = FSOKANUERHMBTIYCWLQPZXVGJD
- B = YRUHQSLDPXNGOKMIEBFZCWVJAT
- C = FVPJIAOYEDRZXWGCTKUQSBNMHL
- B Thin = ENKQAUYWJICOPBLMDXZVFTHRGS
- C Thin = RDOBJNTKVEHMLFCWZAXGYIPSUQ
- 接触点 = ABCDEFGHIJKLMNOPQRSTUVWXYZ
转子可以有凹槽,表示下一个转子前进的位置。例如:Q位置的凹槽意味着,如果转子从Q步进到R,下一个转子就前进。这些位置是
- I = Q
- II = E
- III = V
- IV = J
- V = Z
- VI, VII, VIII = Z + M
每个转子一次只能在一个位置使用。I..VIII转子可以安装在位置1, 2或3,而Beta和Gamma转子只能用于位置4。另外,Beta和Gamma只能与B Thin或C Thin反射器一起使用,其他只能与B或C反射器一起使用。
重要
这些条件仅适用于想要正确模拟原始恩尼格玛的情况。此实现允许用户以任何顺序设置转子,因此用户需要负责转子的顺序。
用法
创建库的新实例
反射器
ReflectorInterface::REFLECTOR_B ReflectorInterface::REFLECTOR_C ReflectorInterface::REFLECTOR_BTHIN ReflectorInterface::REFLECTOR_CTHIN
转子
RotorInterface::ROTOR_I RotorInterface::ROTOR_II RotorInterface::ROTOR_III RotorInterface::ROTOR_IV RotorInterface::ROTOR_V RotorInterface::ROTOR_VI RotorInterface::ROTOR_VII RotorInterface::ROTOR_VIII RotorInterface::ROTOR_BETA RotorInterface::ROTOR_GAMMA
代码示例
use Tankfairies\Enigma\Enigma; $enigma = new Enigma(); $enigma ->installRotors(new Rotor()) ->installReflector(new Reflector()) ->installWiring(new Wiring()) ->installPlugboard(new Plugboard()) ->installAplhabet(new Enigma\Alphabet()); $enigma ->setModel(EnigmaInterface::MODEL_KMM3) ->setRotors([ RotorInterface::ROTOR_I, RotorInterface::ROTOR_II, RotorInterface::ROTOR_III ]) ->setReflector(ReflectorInterface::REFLECTOR_B) ->initialise(); $this->enigma->setPosition(RotorInterface::ROTOR_I, "Q"); $this->enigma->setPosition(RotorInterface::ROTOR_II, "E"); $this->enigma->setPosition(RotorInterface::ROTOR_III, "V"); $this->enigma->setRingstellung(RotorInterface::ROTOR_I, "A"); $this->enigma->setRingstellung(RotorInterface::ROTOR_II, "A"); $this->enigma->setRingstellung(RotorInterface::ROTOR_III, "A"); $this->enigma->plugLetters("B", "Q"); $this->enigma->plugLetters("C", "R"); $this->enigma->plugLetters("D", "I"); $this->enigma->plugLetters("E", "J"); $this->enigma->plugLetters("K", "W"); $this->enigma->plugLetters("M", "T"); $this->enigma->plugLetters("O", "S"); $this->enigma->plugLetters("P", "X"); $this->enigma->plugLetters("U", "Z"); $this->enigma->plugLetters("G", "H"); $message = str_split("HELLOXWORLD"); $encoded = ''; foreach ($message as $character) { $encoded .= $this->enigma->encodeLetter($character); }
进一步阅读
http://en.wikipedia.org/wiki/Enigma_machine
http://users.telenet.be/d.rijmenants/
致谢
感谢来自Mustache Lab的Rafal Masiarek,因为这是本项目的灵感来源。 https://github.com/MustacheLab/PHP-Enigma
版权和许可
tankfairies/rulesengine 库版权所有(c)2021 Tankfairies (https://tankfairies.com),并许可在MIT许可(MIT)下使用。