tankfairies/enigma
Composer 安装命令:
composer require tankfairies/enigma
包简介
Enigma Engine
README 文档
README
Enigma
Installation
Install with Composer:
composer require tankfairies/enigma
Details
This package provides the funtionality of 3 different Enigma models:
- Wehrmacht / Luftwaffe 3 rotor model
- Kriegsmarine 3 rotor model
- Kriegsmarine 4 rotor model
Each model can be equipped with a different set of rotors and refelctors. All in all are 10 types of rotors and 4 types of refelctors available.
- Wehrmacht / Luftwaffe 3 rotor model uses:
- rotors: I, II, III, IV, V
- reflectors: B, C
- Kriegsmarine 3 rotor model uses:
- rotors: I, II, III, IV, V, VI, VII, VIII
- reflectors: B, C
- Kriegsmarine 4 rotor model uses:
- rotors: I, II, III, IV, V, VI, VII, VIII, Beta, Gamma
- reflectors: B Thin, C Thin
Each rotor and reflector provides a unique wiring, which can not be changed. Settings are:
- Contacts = 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
- Contacts = ABCDEFGHIJKLMNOPQRSTUVWXYZ
Rotors can have notches, which indicate the position where the next rotor is advanced. e.g.: Notch at position Q means, if rotor steps from Q to R, the next rotor is advanced. These positions are:
- I = Q
- II = E
- III = V
- IV = J
- V = Z
- VI, VII, VIII = Z + M
Each Rotor can be only used in one position at a time. Rotors I..VIII can be mounted at position 1, 2 or 3, wherelse rotors Beta and Gamma can only be used at position 4. Aditionally, Beta and Gamma can only be used in combination with reflector B Thin or C Thin, the others only with reflector B or C.
IMPORTANT
These conditions only apply if a proper emulation of the original Enigma is desired. This implementation allows to setup the rotors in any order, so its up to the user to take care of the order of rotors.
Usage
Instantiate a new instance of the library:
Reflectors
ReflectorInterface::REFLECTOR_B ReflectorInterface::REFLECTOR_C ReflectorInterface::REFLECTOR_BTHIN ReflectorInterface::REFLECTOR_CTHIN
Rotors
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
Code Example
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); }
Further Reading
http://en.wikipedia.org/wiki/Enigma_machine
http://users.telenet.be/d.rijmenants/
Credit
Thanks to Rafal Masiarek from Mustache Lab, as this was the inspiriation for this project. https://github.com/MustacheLab/PHP-Enigma
Copyright and license
The tankfairies/rulesengine library is Copyright (c) 2021 Tankfairies (https://tankfairies.com) and licensed for use under the MIT License (MIT).
tankfairies/enigma 适用场景与选型建议
tankfairies/enigma 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 08 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「encryption」 「enigma」 「code breaking」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tankfairies/enigma 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tankfairies/enigma 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tankfairies/enigma 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Memio's PrettyPrinter, used to generate PHP code from given Model
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
Allows installation of Laravel where the PHP Mcrypt extension is not available. Provides encryption using OpenSSL, or by disabling encryption entierly.
High-level cryptographic primitives and security utilities for Maatify systems including password hashing, reversible encryption, HKDF key derivation, and key rotation.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-08-03