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

v3.0.0

Published

An Enigma Machine Simulator

Downloads

11

Readme

Enigma Simulator

An npm module for Enigma Machines. It can simulate a Wehrmacht Enigma I and Kriegsmarine M3 and M4 variants.

Install

npm install enigma-simulator

Example Usage

Require the enigma-simulator module:

var enigma = require('enigma-simulator');

Create a Wehrmacht Enigma I Machine with a B reflector and rotors III, II, I with default positions and ring settings:

var e1 = enigma();
e1.encodeString('ABC'); // 'FUV'

Or create an Enigma machine with your own settings (rotors, positions, ringSettings, reflector, plugboardPairs):

var m3 = enigma(['IV', 'I', 'III'], [3, 5, 20], [7, 12, 14], 'C', 'AS TH LR');
m3.encodeString('ABC'); // 'IRD'

Create a Kriegsmarine M4 Enigma Machine:

var m4 = enigma(['Gamma','III','II','I'], [0,0,0,0], [0,0,0,0], 'BThin');
m4.encodeString('ABC'); // 'BPF'

Documentation

enigma()

Syntax

enigma(rotors, positions, ringSettings, reflector, plugboardPairs)

Output

Returns an instance of EnigmaMachine.

Parameters

rotors Optional. An array of strings which represent the rotor types to use in which position (left to right). Available rotors are:

| Rotor | Encoding | Turnover | Notes | | --- | --- | --- | --- | | 'I' | EKMFLGDQVZNTOWYHXUSPAIBRCJ | Q | Wehrmacht Enigma I | | 'II' | AJDKSIRUXBLHWTMCQGZNPYFVOE | E | Wehrmacht Enigma I | | 'III' | BDFHJLCPRTXVZNYEIWGAKMUSQO | V | Wehrmacht Enigma I | | 'IV' | ESOVPZJAYQUIRHXLNFTGKDCMWB | J | Kriegsmarine M3 | | 'V' | VZBRGITYUPSDNHLXAWMJQOFECK | Z | Kriegsmarine M3 | | 'VI' | JPGVOUMFYQBENHZRDKASXLICTW | Z & M | Kriegsmarine M4 | | 'VII' | NZJHGRCXMYSWBOUFAIVLPEKQDT | Z & M | Kriegsmarine M4 | | 'VIII' | FKQHTLXOCBJSPDZRAMEWNIUYGV | Z & M | Kriegsmarine M4 | | 'Beta' | LEYJVCNIXWPBQMDRTAKZGFUHOS | | Kriegsmarine M4, fourth rotor, didn't rotate, used with thin reflectors | | 'Gamma' | FSOKANUERHMBTIYCWLQPZXVGJD | | Kriegsmarine M4, fourth rotor, didn't rotate, used with thin reflectors |

The array expects 3 items (to simulate the Wehrmacht Enigma I or Kriegsmarine M3) or 4 items (for the Kriegsmarine M4). If the Enigma Machine is initialized with four rotors, it is assumed the left-most rotor is a Beta/Gamma rotor in an M4. Therefore the left-most rotor will not rotate.

Defaults to [III, II, I].

positions Optional. An array of integers [0..25] which represent the positions of the rotors. Defaults to [0, 0, 0].

ringSettings Optional. An array of integers [0..25] which represent the ring settings (or Ringstellung) of the rotors. Defaults to [0, 0, 0].

reflector Optional. A string which represents the reflector type used. Available reflectors are:

| Reflector | Encoding | Notes | | --- | --- | --- | | 'B' | YRUHQSLDPXNGOKMIEBFZCWVJAT | | | 'C' | FVPJIAOYEDRZXWGCTKUQSBNMHL | | | 'BThin' | ENKQAUYWJICOPBLMDXZVFTHRGS | Kriegsmarine M4 | | 'BThin' | RDOBJNTKVEHMLFCWZAXGYIPSUQ | Kriegsmarine M4 |

Defaults to 'B'.

plugboardPairs Optional. A string containing a list of pairs of letters separated by spaces. This represents the letters that should be switched on the plugboard (or Steckerbrett). Defaults to an empty string (no substitutions).

EnigmaMachine.encodeString()

Syntax

enigmaMachine.encodeString(text)

Output

Returns a string which is the encoding/decoding of text.

Parameters

text The text to encode/decode. The text is required to only contain uppercase letters from the latin alphabet.

Learn More

A good introduction to the Enigma Machine is this Numberphile video. You can find out more about the details of the inner workings of the machine on Dirk Rijmenants' website. One of the more complex quirks of the Enigma Machine's mechanism is the "double step". You can see this in action in this video.

Contributors 🎉

mrpjevans