enigma-machine
v1.1.3
Published
Enigma simulator in Typescript
Downloads
6
Readme
enigma-machine
Enigma simulator in Typescript
Installation and Importation
Installation
$ npm install enigma-machine
Importation
// CommunJS
const EnigmaMachine = require('enigma-machine');
// Browser
<script src="https://unpkg.com/[email protected]/build/browser.js"></script>
Machine creation
Creating a Rotor
const rotor1 = new EnigmaMachine.Rotor(/* RotorConfiguration Object */);
Creating a Reflector
const reflector = new EnigmaMachine.Reflector(/* ConnectionMap Object */);
Creating a Plugboard
const plugboard = new EnigmaMachine.Plugboard(/* ConnectionMap Object */);
❓ See how to generate a random ConnectionMap
Creating the Enigma Machine
const enigma = new EnigmaMachine.Enigma([rotor1, rotor2, rotor3], reflector, plugboard);
Creating an Enigma Machine from an EnigmaConfiguration
const enigma = new EnigmaMachine.Enigma.generateFromEnigmaConfig(/* EnigmaConfiguration Object */);
:warning: Rotor list must contain 3 rotors
Message
Calculate a message with Enigma
const myMessage = enigma.calculateString('helloworld');
// Return 'lumquxgpzf' with a config that I lost :D
const mySecondMessage = enigma.calculateString('lumquxgpzf');
// Return 'helloworld' with the same config
See test file on GitHub
Generating configurations and ConnectionMaps
Generating a Rotor configuration
const rotorConfiguration = EnigmaMachine.generateRotorConfiguration();
:warning: If you are creating manually the RotorConfiguration
you can't use the generateConnectionMap
method !
Generating a ConnectionMap (used to configure a Reflector or a Plugboard)
// For a Reflector
const reflectorConnectionMap = EnigmaMachine.generateConnectionMap();
// const reflector = new EnigmaMachine.Reflector(reflectorConnectionMap);
// For a Plugboard
const plugboardConnectionMap = EnigmaMachine.generateConnectionMap();
// const plugboard = new EnigmaMachine.Plugboard(plugboardConnectionMap);
Generating an EnigmaConfiguration
const enigmaConfig = EnigmaMachine.generateEnigmaConfiguration();
:warning: If you want to create two Enigma machines with the same configuration (for crypting and "decrypting" for example) you can't use the same object ! You have to create an another object with the same content. Why you would ask... the answer is very simple because Javascript is a piece of 💩 (btw I lost 4 hours because of this 😡 )
Todo
- Improve the browser version of the lib (because I'm bundling it manually) 🖥️
- ~~Nothing (I hope) 😀~~