npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

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) 😀~~