declare module "enigma/consts" { export const STANDARD_ALPHABET: string; } declare module "enigma/Encoder" { /** * This is the base class for an encoder. The default implementation of the * encode method is to return the input as the output */ export default class Encoder { /** * Constructor for the base encoder * * @param {string} name * @param {ComponentType} type * @param {EncoderSetup} settings */ constructor(name: string, type: ComponentType, settings: EncoderSetup); name: string; type: ComponentType; alphabet: string; contactCount: number; /** @type {{[name: string]: Listener}} */ listeners: { [name: string]: Listener; }; /** * given a connector number, normalize it to be between 0 and 25 inclusive. * * @param {Number} connector the connector being normalized * * @returns {Number} value between 0 and 25 */ normalize(connector: number): number; /** * * @param {string} letter * * @returns {boolean} */ verifyLetter(letter: string): boolean; /** * Call this method to convert a letter to a connector value * * @param {string} letter * @returns {number | undefined} */ letterToConnector(letter: string): number | undefined; /** * Call this method to turn a connector to a letter value * * @param {number} connector * @returns {string | undefined} */ connectorToLetter(connector: number): string | undefined; /** * Given an alphabetic connection map, convert that into an array of * numbers. The index into the array or string is the input connector, and * the value at that position is the output connector * * @param {String} map connections map. * @returns {Array.} the numerical map */ makeMap(map: string): Array; /** * given an existing connection map from input to out put, create a new map * that has the connections going in the other direction, output to input. * * @param {Array.} map connection map * @returns {Array.} the reversed map */ makeReverseMap(map: Array): Array; /** * Call this method to convert the input connector number to the output in * the given direction The default encode method just passes the input value * through * * @param {Direction} _direction either right for moving towards the reflector * or left if moving back * @param {Number} input the specific connection receiving an input * * @returns {Number} The translated output connector number */ encode(_direction: Direction, input: number): number; /** * * @param {number | string} input * @param {Direction} direction */ fireInput(input: number | string, direction: Direction): void; /** * * @param {number | string} output * @param {Direction} direction */ fireOutput(output: number | string, direction: Direction): void; /** * * @param {number | string} input * @param {number | string} output * @param {Direction} direction */ fireTranslate(input: number | string, output: number | string, direction: Direction): void; /** * * @param {number | string} input * @param {number | string} output * @param {Direction} direction */ fireEncodeSet(input: number | string, output: number | string, direction: Direction): void; /** * Call this method to add a function to be called when important events * happen to a component. The name can be used to later remove the listener * * @param {string} name - the name of the listener * @param {Listener} cb - the function to be called. */ listen(name: string, cb: Listener): void; /** * Call this method to remove a listener * * @param {string} name - the name of the listener */ unlisten(name: string): void; /** * Call this method to call any event listeners * * @param {EventName} event - the event being fired * @param {String} name - the name of the component firing the event * @param {EventData} data - the event data */ fire(event: EventName, name: string, data: EventData): void; } } declare module "enigma/EntryDisc" { /** * This is the class for an entry disc. Entry discs are fixed disks of connector * pins. */ export default class EntryDisc extends Encoder { /** * Constructor for the entry disc. * * @param {String} name the name of this entry disc * @param {EncoderSetup} settings contains the alphabet being used, and the map * between input and output contacts */ constructor(name: string, settings: EncoderSetup); rightMap: number[]; leftMap: number[]; } import Encoder from "enigma/Encoder"; } declare module "enigma/PlugBoard" { /** * This class represents the plugboard. There is only one type of plugboard */ export default class PlugBoard extends Encoder { /** * Constructor for the plugboard. * * @param {String} name the name for the plugboard, defaults to 'plugboard' * @param {EncoderSetup} [settings] the settings for the plugboard. Only needed if * using an alternate alphabet */ constructor(name?: string, settings?: EncoderSetup); map: string; rightMap: any[]; leftMap: any[]; plugs: string; /** * Call this method to configure the plug board. This will be used to * provide the plug connections * * @param {Plugs} plugs the configuration options for the plug * board */ configure(plugs?: Plugs): void; } import Encoder from "enigma/Encoder"; } declare module "enigma/Rotor" { /** * Create an instance of this class to construct a Rotor object. The Rotor class * encapsulates many of the peculiar behaviors of the Enigma. All connector * values here are specified in physical space. */ export default class Rotor extends Encoder { /** * This is the constructor for the rotor. * * @param {String} name the name of the rotor; under normal circumstances * this will be the string 'rotor-' plus the standard name for the rotor, * for example 'rotor-IV' * @param {RotorSetup} settings an object that contains the various options that * define the the rotor and how it is configured. */ constructor(name: string, settings: RotorSetup); map: string[]; rightMap: number[]; leftMap: number[]; length: number; ringOffset: number; turnoverLookup: number[]; offset: number; fixed: boolean; turnovers: string; _turnovers: Set; /** * Call this method to select the initial rotation of the rotor. This is a * letter offset from the logical 0 connector. The initial rotation will * also take into account the ring setting * * @param {String} connector This is a letter value that corresponds to what * would appear in the rotation window. This value will be adjusted for the * ring setting. */ setStartPosition(connector: string): void; /** * Call this method to step the rotor * * @returns {Boolean} true if the next rotor should be stepped */ step(): boolean; /** * Call this method to see if the next step on this rotor will lead to * turnover. The Enigma class will call this on the middle rotor to handle * double stepping. * * @returns true if this rotor will turnover on the next step */ willTurnover(): boolean; shouldTurnover(): boolean; /** * Call this method to find whether this is a fixed rotor. This is used for * the non stepping rotors--beta and gamma--that are used in the M4 * @returns */ isFixed(): boolean; } import Encoder from "enigma/Encoder"; } declare module "enigma/Reflector" { /** * Make in instance of this class to construct a reflector */ export default class Reflector extends Encoder { /** * constructor for the reflector class. * * @param {String} name the name of the reflector instance * @param {EncoderSetup} settings The definition of the reflector */ constructor(name: string, settings: EncoderSetup); map: number[]; } import Encoder from "enigma/Encoder"; } declare module "enigma/Inventory" { const _default: Inventory; export default _default; /** * This is the class used to manage the standard inventory of components. An * instance of this class is exported as the default of this module */ class Inventory { entryDiscs: {}; /** @type {{[name: string]: RouterInventorySpec}}*/ rotors: { [name: string]: RouterInventorySpec; }; reflectors: {}; /** * Call this method to add a new Rotor type to the inventory. * * @param {String} name the name of the rotor being added. This name will be * used when specifying the rotors to use for the Enigma configuration. * @param {String} map a string specifying the connector mapping. The index * of the string is the logical coordinate of the connector, the character * at that index is the output connector. To be exact, it would be the * position of that character in the given alphabet. So, in the map ' * EKMFLGDQVZNTOWYHXUSPAIBRCJ', input connector 0 would map to output * connector 4 and input connector 1 would map to output connector 10. * Remember that the connectors are numbered starting at 0. * @param {String} turnovers this is a string of characters representing the * turnover locations on the disk. These letter would be the value shown in * the window to during turnover. In Rotor I this is 'Q' in rotors VI, VII, * and VIII there are two turnover locations, 'M' and 'Z'. Pass an empty * string if this is a fixed rotor */ addRotor(name: string, map: string, turnovers: string): void; /** * Call this method to add a new reflector definition. * * @param {String} name this is the name that will be used to reference this * reflector when constructing an Enigma class. * @param {String} map the mapping between connectors. this uses the same * format used in the addRotor method */ addReflector(name: string, map: string): void; /** * Call this method to add a new entry disc. There was only one used in the * standard military models, but there were other versions that defined it * differently. * * @param {*} name this is the name that will be used to reference this * entry disc when constructing an Enigma class. * @param {*} map the mapping between connectors. this uses the same format * used in the addRotor method */ addEntryDisc(name: any, map: any): void; /** * Call this method to get the setup for a defined rotor. * * @param {String} name the name of the rotor as it was added to the * inventory. * * @returns {Object} the rotor definition * @property {String} map the connection map for the rotor * @property {String} turnovers the locations where turnovers happen */ getRotor(name: string): any; /** * Call this method to get the setup for a defined reflector. * * @param {String} name the name of the reflector as it was added to the * inventory. * @returns {Object} the reflector definition * @property {String} the connection map for the reflector */ getReflector(name: string): any; /** * Call this method to get the setup for a defined entry disc. * * @param {String} name the name of the entry disc as it was added to the * inventory. * @returns {Object} the entry disc definition * @property {String} the connection map for the entry disc */ getEntryDisc(name: string): any; /** * Call this method to get the names of all the rotors in the inventory * * @param {boolean} [fixed] - if specified it returns only the names of * routers filtered on if they are fixed or not, otherwise it returns all * * @returns {string[]} the names of the rotors */ getRotorNames(fixed?: boolean): string[]; } } declare module "enigma/Enigma" { /** * Construct this class to get a new instance of the Enigma. Many of the * parameters to the constructor and the config method reference the names of * standard Enigma parts. These are retrieved from the Inventory instance */ export default class Enigma extends Encoder { /** * The constructor for the Enigma. This represents the unconfigurable * settings of the device. * * @param {string} name * @param {EnigmaSetup} settings */ constructor(name: string, settings: EnigmaSetup); plugboard: PlugBoard; entryDisc: EntryDisc; reflector: Reflector; length: number; /** @type {Rotor[]} */ _rotors: Rotor[]; /** @type {{[rotor: number]: boolean}} */ pending: { [rotor: number]: boolean; }; /** @type {Encoder[]} */ encoders: Encoder[]; /**@type {SimplifiedConfiguration & {reflector: string}} */ _configuration: SimplifiedConfiguration & { reflector: string; }; /** * the configured rotors * * @return {Rotor[]} */ get rotors(): Rotor[]; /** * @returns {SimplifiedConfiguration & {reflector: string}} */ get configuration(): SimplifiedConfiguration & { reflector: string; }; /** * Configure the Enigma for encoding. * * @param {EnigmaConfiguration} settings - the configuration of the Enigma. * These settings represent the aspects of the Enigma that can can change for daily * configuration. */ configure(settings: EnigmaConfiguration): void; /** * Call this method to "step" the rotors one time. This method will manage the * stepping between all rotors */ step(): void; /** * Call this method to set the starting rotation for the messages to encrypt * * @param {number[]|string} setup - length of the string or the array * should match the number of rotors and are given left to right. If start * is a string then the letters of the string specify the start value seen * in the window for the corresponding rotor. If it is an array then each * number will be the one-based rotation. */ setStart(setup: number[] | string): void; /** * Call this method to simulate a keypress on the Enigma. This will output * the encoded letter * * @param {String} letter the key pressed * @returns {String | undefined} the encoded letter */ keyPress(letter: string): string | undefined; /** * Call this shortcut method to encode a whole string * * @param {String} start the starting position for the rotors * @param {String} text the text to encode * * @returns {String} the encoded string. */ translate(start: string, text: string): string; } import Encoder from "enigma/Encoder"; import PlugBoard from "enigma/PlugBoard"; import EntryDisc from "enigma/EntryDisc"; import Reflector from "enigma/Reflector"; import Rotor from "enigma/Rotor"; } declare module "enigma/standardInventory" { export namespace entryDiscDefinitions { let _default: string; export { _default as default }; } export namespace rotorDefinitions { namespace I { let map: string; let turnovers: string; } namespace II { let map_1: string; export { map_1 as map }; let turnovers_1: string; export { turnovers_1 as turnovers }; } namespace III { let map_2: string; export { map_2 as map }; let turnovers_2: string; export { turnovers_2 as turnovers }; } namespace IV { let map_3: string; export { map_3 as map }; let turnovers_3: string; export { turnovers_3 as turnovers }; } namespace V { let map_4: string; export { map_4 as map }; let turnovers_4: string; export { turnovers_4 as turnovers }; } namespace VI { let map_5: string; export { map_5 as map }; let turnovers_5: string; export { turnovers_5 as turnovers }; } namespace VII { let map_6: string; export { map_6 as map }; let turnovers_6: string; export { turnovers_6 as turnovers }; } namespace VIII { let map_7: string; export { map_7 as map }; let turnovers_7: string; export { turnovers_7 as turnovers }; } namespace Beta { let map_8: string; export { map_8 as map }; let turnovers_8: string; export { turnovers_8 as turnovers }; } namespace Gamma { let map_9: string; export { map_9 as map }; let turnovers_9: string; export { turnovers_9 as turnovers }; } } export const reflectorDefinitions: { A: string; B: string; C: string; 'Thin-B': string; 'Thin-C': string; }; } declare module "enigma/index" { export { default as Enigma } from "./Enigma.js"; export { default as EntryDisc } from "./EntryDisc.js"; export { default as inventory } from "./Inventory.js"; export { default as PlugBoard } from "./PlugBoard.js"; export { default as Reflector } from "./Rotor.js"; } declare module "generator/hamlet" { export default sentences; const sentences: string[]; } declare module "utils/Random" { const _default: Random; export default _default; /** * This class implements a pseudorandom number generator that can be given a * seed to produce a consistent sequence of numbers. This algorithm is * inappropriate for real cryptographic purposes, but allows the production of * output that can be consistently reproduced. * * This algorithm was stolen from the product Delphi. */ class Random { randSeed: number; /** * Call this method to set the seed value for the randomizer. The initial value * will be the current time in milliseconds. * * @param {Number} value for the seed, */ randomize(value: number): void; /** * Call this method to get a random number. If passed a value, the return * will be an integer between 0 and that number - 1. without it will be a * decimal value between 0 and < 1. * * @param {Number} [limit] if passed the upper boundary of the integer - 1 * * @returns {Number} the randomized value as either an integer or a decimal * value depending on how it was called. */ random(limit?: number): number; /** * Generate a random number using a bell curve. The curve is created using * the analogy of dice. For example, a random number built with two six * sided dice will have the peak of the curve at 7 with 2 and 12 being at * the bottom. * * @param {number} dice - how many random numbers to pick * @param {number} faces - the range, from 1 - faces, of the number * @param {boolean} [zeroBased] - if true, the random range for each die will be from 0 - faces-1 * * @return {number} the random number */ randomCurve(dice: number, faces: number, zeroBased?: boolean): number; /** * call this method to pick a random number from an array and remove it * * @template T * @param {T[]} list the array of items to choose from * * @returns {T} the chosen item */ pickOne(list: T[]): T; /** * Call this method to pick two items from a given list. The items are * removed from the array. If the array is less than two items then it * will return either an empty array or an array with one element. * * @template T * * @param {T[]} list the array of items to choose * @returns {T[]} the two chosen items */ pickPair(list: T[]): T[]; /** * Call this method to choose a given number of items from a list. The items * are removed. * * @template T * * @param {Number} count the number of items to pick * @param {T[]} list the list of items to choose from * * @returns {T[]} the chosen items */ pick(count: number, list: T[]): T[]; /** * Call this method to randomly pick a set of item pairs. The items * will be removed from the list. * * @template T * @param {Number} count the number of pairs to pick * @param {T[]} list the list of items to choose from *, * @returns {T[][]}} the item pairs chosen. Each pair is an array of * two items from the list */ pickPairs(count: number, list: T[]): T[][]; /** * Call this method to chose a random item from a list. The item is not * removed. * * @template T * * @param {T[]} list the list of items to choose from * @returns {T} the chosen item */ chooseOne(list: T[]): T; /** * Call this method to pick a pair of items from the given list. The items * are guaranteed to be unique. * * @template T * * @param {T[]} list - the list of items * @returns {T[]} */ choosePair(list: T[]): T[]; /** * Call this method to return a random list of contiguous items from the * given list. The items are not removed. * * @template T * @param {number} count * @param {T[]} list * * return {T[]} */ chooseRange(count: number, list: T[]): string; /** * Call this method to randomly pick a subset of items from a list. The * items are not removed. * * @template T * * @param {Number} count the number of items to choose * @param {T[]} list the list of items to choose from * * @returns {T[]} the list of items chosen */ choose(count: number, list: T[]): T[]; } } declare module "generator/Generator" { /** * Use this class to generate random enigma configurations and messages. The * methods in this class all the use the `Random` object, which can be seeded to * produce a reproducible output */ export default class Generator { /** * Call this method to turn a string into valid characters for encryption, * which is just the letters A-Z. * * @param {String} text the original text * @returns {String} the text that has been normalized to what the Enigma * can process */ cleanMessage(text: string): string; /** * Call this method to break a string into groups of five letters with a * space between them. * * @param {string} text - the original text * @param {number} [size] - the size of the text groups, defaults to 5 * * @returns {string} the segmented string */ groupText(text: string, size?: number): string; /** * Call this method to generate the given number of sentences. The sentences * are pulled from the text of Hamlet. * * @param {Number} count the number of sentences * @returns {String} the sentences separated by a ' '; */ generateSentences(count: number): string; /** * Call this method to get the possible setup and configuration options for * the given model * * @param {Model} model * * @returns {ModelOptions} */ getModelOptions(model: Model): ModelOptions; /** * Call this method to generate a random Enigma configuration * * @param {GeneratorSetup} [setup] options for settings * @returns {SimplifiedConfiguration} the Enigma settings. */ generateEnigmaConfiguration(setup?: GeneratorSetup): SimplifiedConfiguration; /** * * @param {string[]} [reflectors] if given, specifies and alternate list of * reflectors. Defaults to ['A', 'B', 'C']; */ createRandomEnigma(model?: string, reflectors?: string[]): Enigma; /** * Call this method to generate a random message text encoded with the given * Enigma. The random text will be a few sentences from Hamlet. * * @param {Enigma} enigma * * @returns {GeneratedMessage} details of the generated text */ generateMessage(enigma: Enigma): GeneratedMessage; } import Enigma from "enigma/Enigma"; } declare module "generator/CodeBook" { /** * Use this class to generate Enigma key sheets and messages using it. The * procedures used were derived from the information at * [Enigma Message Procedures](https://www.ciphermachinesandcryptology.com/en/enigmaproc.htm) */ export default class CodeBook { /** * Constructor for the `CodeBook` class. * @param {Enigma} enigma - all encryption will be done using this configured Enigma */ constructor(enigma: Enigma); enigma: Enigma; indicators: {}; generator: Generator; /** * Call this method to provide a new configuration to the enigma * * @param {SimplifiedConfiguration} config */ configure(config: SimplifiedConfiguration): void; reset(): void; /** * Call this method to create a three letter string as an identifier for a * a day in a key sheet * * @returns {String} the string */ makeIndicator(): string; /** * Call this method to create a single days configuration for a key sheet. * This an Enigma configuration plus the other metadata. * * @param {number} day the day of the month * * @returns {KeySheetLine} One line of a key sheet */ generateDay(day: number): KeySheetLine; /** * Call this method to construct a key sheet for the given number of days * * @param {Number} days the number of days on the key sheet * @returns {KeySheetLine[]} the array of day objects */ generateKeySheet(days: number): KeySheetLine[]; /** * Call this method to process one sub-message from a longer message. This is * part of code to generate a message as the Enigma would have been used. * * @param {string[]} indicators the three letter code that can be sent to * reference the configuration of the Enigma. These will be used to cross * reference the message to the machine configuration on the key sheet * @param {String} text the cleaned up string to be encoded * * @returns {MessagePart} the encoded message segment */ encodeOnePart(indicators: string[], text: string): MessagePart; /** * Call this method to generate a full message based on the data in a key * sheet. The message constructed reflects an actual message as the Enigma * was really used. An individual message cannot be more than 250 * characters, so longer messages are broken into multiple parts, each one * encoded with a unique key * * @param {KeySheetLine[]} sheet a key sheet generated using generateKeySheet * @param {number} [dayIdx] - if provided, specifies the day of the month for the message * @param {string} [text] - if provided, this is the text of the message to generate * @returns {KeyBookMessage} a list of encoded sub messages */ generateMessage(sheet: KeySheetLine[], dayIdx?: number, text?: string): KeyBookMessage; /** * Call this method to generate a given number of messages based on a * generated key sheet * * @param {Object} sheet the generated key sheet * @param {Number} count - the number of messages to generate * * @returns {Array} the list of generated messages */ generateMessages(sheet: any, count: number): any[]; } import Enigma from "enigma/Enigma"; import Generator from "generator/Generator"; } declare module "generator/index" { export { default as Generator } from "./Generator.js"; export { default as CodeBook } from "./CodeBook.js"; export { default as Random } from "../utils/Random.js"; } declare module "index" { export * from "enigma/index"; export * from "generator/index"; } declare module "enigma/tests/EnigmaData" { export namespace enigmaData { let sampleFieldMessages: ({ source: string; model: string; setup: { reflector: string; rotors: string[]; ringSettings: number[]; plugs: string; }; message: { key: string; encoded: string; decoded: string; }; } | { source: string; model: string; setup: { reflector: string; rotors: string[]; ringSettings: string; plugs: string; }; message: { key: string; encoded: string; decoded: string; }; })[]; let sampleVerifiedMessages: { verified: string[]; model: string; setup: { rotors: string[]; plugs: string; ringSettings: number[]; reflector: string; }; message: { key: string; encoded: string; decoded: string; }; }[]; } } declare module "enigma/tests/EnigmaSpec" { export {}; } declare module "enigma/tests/PlugBoardData" { export namespace plugBoardData { let alphabet: string; let plugSettings: string; } } declare module "enigma/tests/PlugBoardSpec" { export {}; } declare module "enigma/tests/RotorData" { export namespace rotorData { namespace createData { let alphabet: string; let map: string; let reverseMap: number[]; let turnovers: string; let turnoversMap: number[]; } namespace I { let map_1: string; export { map_1 as map }; let turnovers_1: string; export { turnovers_1 as turnovers }; } } } declare module "enigma/tests/RotorSpec" { export {}; }