1.1.3 ā€¢ Published 3 years ago

enigma-machine v1.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

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 */);

: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) šŸ˜€
1.1.1

3 years ago

1.1.0

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago