PHPackages                             tankfairies/enigma - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. tankfairies/enigma

ActiveLibrary[Security](/categories/security)

tankfairies/enigma
==================

Enigma Engine

v1.3(4y ago)032MITPHPPHP ^7.3

Since Aug 3Pushed 4y ago1 watchersCompare

[ Source](https://github.com/tankfairies/enigma)[ Packagist](https://packagist.org/packages/tankfairies/enigma)[ Docs](https://tankfairies.com/)[ RSS](/packages/tankfairies-enigma/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

[![Latest Stable Version](https://camo.githubusercontent.com/f546dec92c3a2b52c5e9c563b4601ffcb2ea4de9b9807a83687b42acad68207e/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f656e69676d612f762f737461626c65)](https://packagist.org/packages/tankfairies/enigma)[![Total Downloads](https://camo.githubusercontent.com/adef345d5c175fdddd29025177f18800aabbd0a9f7bba2c9344513a1daa9b84f/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f656e69676d612f646f776e6c6f616473)](https://packagist.org/packages/tankfairies/enigma)[![Latest Unstable Version](https://camo.githubusercontent.com/77e07f437e8ec0b51d997ad91e2d2c474d93271ea9cfb9d719843966d3fec0ad/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f656e69676d612f762f756e737461626c65)](https://packagist.org/packages/tankfairies/enigma)[![License](https://camo.githubusercontent.com/5fb5cefc430556620dd380a4d16a851177c8a5da3d97faa3d8256c52f4d007ed/68747470733a2f2f706f7365722e707567782e6f72672f74616e6b666169726965732f656e69676d612f6c6963656e7365)](https://packagist.org/packages/tankfairies/enigma)[![Build Status](https://camo.githubusercontent.com/3fc637f2a53fbd313f239c3b6aed6a795cbb53b4f15618e7e8d1cfb4177bd435/68747470733a2f2f7472617669732d63692e636f6d2f74616e6b666169726965732f656e69676d612e7376673f6272616e63683d6d61696e)](https://travis-ci.com/tankfairies/enigma)

Enigma
======

[](#enigma)

Installation
------------

[](#installation)

Install with [Composer](https://getcomposer.org/):

```
composer require tankfairies/enigma
```

Details
-------

[](#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
-----

[](#usage)

Instantiate a new instance of the library:

### Reflectors

[](#reflectors)

```
ReflectorInterface::REFLECTOR_B
ReflectorInterface::REFLECTOR_C
ReflectorInterface::REFLECTOR_BTHIN
ReflectorInterface::REFLECTOR_CTHIN
```

### Rotors

[](#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

[](#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
---------------

[](#further-reading)

[http://en.wikipedia.org/wiki/Enigma\_machine](http://en.wikipedia.org/wiki/Enigma_machine)

Credit
------

[](#credit)

Thanks to Rafal Masiarek from Mustache Lab, as this was the inspiriation for this project.

Copyright and license
---------------------

[](#copyright-and-license)

The tankfairies/rulesengine library is Copyright (c) 2021 Tankfairies () and licensed for use under the MIT License (MIT).

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

4

Last Release

1744d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/761e80f0c4632541e235d7d45128d65ace90c65e3c799c11c36a120155eaad58?d=identicon)[tankfairies](/maintainers/tankfairies)

---

Top Contributors

[![tankfairies](https://avatars.githubusercontent.com/u/50480804?v=4)](https://github.com/tankfairies "tankfairies (6 commits)")

---

Tags

encryptionenigmacode breaking

###  Code Quality

TestsCodeception

### Embed Badge

![Health badge](/badges/tankfairies-enigma/health.svg)

```
[![Health](https://phpackages.com/badges/tankfairies-enigma/health.svg)](https://phpackages.com/packages/tankfairies-enigma)
```

###  Alternatives

[phpseclib/phpseclib

PHP Secure Communications Library - Pure-PHP implementations of RSA, AES, SSH2, SFTP, X.509 etc.

5.6k434.8M1.3k](/packages/phpseclib-phpseclib)[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[paragonie/ciphersweet

Searchable field-level encryption library for relational databases

4641.2M21](/packages/paragonie-ciphersweet)[ass/xmlsecurity

The XmlSecurity library is written in PHP for working with XML Encryption and Signatures

955.6M30](/packages/ass-xmlsecurity)[pear/crypt_gpg

Provides an object oriented interface to the GNU Privacy Guard (GnuPG). It requires the GnuPG executable to be on the system.

954.4M10](/packages/pear-crypt-gpg)[soved/laravel-gdpr

GDPR compliance with ease

299127.5k2](/packages/soved-laravel-gdpr)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
