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-sim

v0.2.0

Published

Simple Enigma M3/M4 simulator.

Downloads

2

Readme

Enigma simulator

This is my attempt at making a simple Enigma simulator. I've looked extensively at lots of web pages, but mostly Wikipedia.

I have focused on functionality, so this simulator behaves as a proper Enigma M3/M4. This includes the "double stepping", which was probably unintended in the original device.

Example

const Enigma = require("enigma");

// Initialise a new Enigma object.
const enigma = new Enigma();

// Now "press" a key and show the result
const encodedLetter = enigma.onKey("A");
console.log(`"A" becomes ${encodedLetter}`);

Please note that creating a new Enigma can throw an error if the options are incorrect. Wrapping it in a try/catch is probably a good idea.

Default configuration

The default configuration is as follows:

{
  "type": 3,
  "rotors": [{
    "type": "I",
    "ringSetting": 1,
    "rotorOffset": "A"
  }, {
    "type": "II",
    "ringSetting": 1,
    "rotorOffset": "A"
  }, {
    "type": "III",
    "ringSetting": 1,
    "rotorOffset": "A"
  }],
  "reflectorType": "B",
  "plugBoard": []
}

This is also available as a JSON file inside the test directory. The plugBoard configuration is an array of letter combinations, like so: ["AE", "PT", "SH"]. Invalid settings will throw an Error. In real life, only 10 pairs were connected.

The rotors in the array are from LEFT to RIGHT. The type defines which Enigma you want to use: 3 for M3, 4 for M4. Upon initalisation, the number of rotors will be checked. You need to pass in 3 rotors for an M3 and 4 rotors for an M4. However, independent of that choice, the first rotor in the array is always the LEFT one as seen by the operator.

When you're configuring the M4, the left rotor (first one in the list) can be of type "beta" or "gamma". Any other rotor at this position will throw an Error.

The rotors that are allowed are I - VIII, and cannot use the same rotor twice in a configuration. The reflector type is either B or C. Different reflectors are used for M3 and M4, but this is handled automatically. To make life a little bit easier, you only have to configure B or C.

API

Constructor

Enigma([options])

options - an optional map that describes the settings of the Enigma.

Encode a single letter

onKey(c)

c - a character that needs to be encoded. Enforced to be a string with length of 1.

Encode an entire message

onMessage(msg)

msg - a message that needs to be encoded. May not be empty, it should have length 1 or greater. It's a convenience function, because Enigma machines didn't have such a feature.

Reinitialise the Enigma

reset()

This resets the Enigma to the initial settings using the configuration passed in through the constructor. It's a convenience function that prevents from having to create another Enigma instance.