PHP code example of tankfairies / enigma
1. Go to this page and download the library: Download tankfairies/enigma library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tankfairies / enigma example snippets
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);
}