Skip to content

janbican/enigma

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Library emulating Enigma machine encryption/decryption in Javascript.

It is used for encrypting and decrypting messages.

Configuration:

  • rotors: I, II, III, IV, V
  • reflectors: B, C
  • plugboard: up to 13 pairs of letters
  • rotor offsets
  • rotor ring settings

More about Enigma

Install

npm install @janbican/enigma

Usage

Default Enigma (rotors: I, II, III, reflector: B, offsets: 'AAA', ringSetings: 'AAA', pairs: [])

const { Enigma, rotors, reflectors } = require('@janbican/enigma')

const enigma = new Enigma()

const cipher = enigma.convertText('HELLOWORLD')
console.log(cipher)
// ILBDAAMTAZ

Enigma with custome settings

const { Enigma, rotors, reflectors } = require('@janbican/enigma')

const enigma = new Enigma({
  left: rotors.IV, middle: rotors.V, right: rotors.I,
  reflector: reflectors.C,
  offsets: 'ZTF', ringSettings: 'FDC',
  pairs: ['TF', 'GJ', 'AP', 'MC']
})

const cipher = enigma.convertText('HELLOWORLD')
console.log(cipher)
// CXCIIRIOGA

API specification in lib/enigma.js

Notes

  • valid alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
  • convertText(text) normalizes text (deletes spaces, interpunction, diacritics)