Skip to content

Latest commit

 

History

History
77 lines (69 loc) · 2.79 KB

README.md

File metadata and controls

77 lines (69 loc) · 2.79 KB

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/enigma-machine@1.1.3/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 */);

⚠️ 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();

⚠️ 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();

⚠️ 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) 😀