@ondoher/enigma 1.0.9 → 1.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -2
- package/tsconfig.json +0 -2
- package/types/index.d.ts +2 -899
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ondoher/enigma",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.11",
|
|
4
4
|
"description": "Enigma machine simulator with tools and documentation to help you build your own.",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./types/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jasmine"
|
|
8
|
+
"test": "jasmine",
|
|
9
|
+
"types": "npx tsc -p tsconfig.json"
|
|
9
10
|
},
|
|
10
11
|
"author": "Glenn Anderson",
|
|
11
12
|
"license": "MIT",
|
package/tsconfig.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,899 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
4
|
-
declare module "enigma/Encoder" {
|
|
5
|
-
/**
|
|
6
|
-
* This is the base class for an encoder. The default implementation of the
|
|
7
|
-
* encode method is to return the input as the output
|
|
8
|
-
*/
|
|
9
|
-
export default class Encoder {
|
|
10
|
-
/**
|
|
11
|
-
* Constructor for the base encoder
|
|
12
|
-
*
|
|
13
|
-
* @param {string} name
|
|
14
|
-
* @param {ComponentType} type
|
|
15
|
-
* @param {EncoderSetup} settings
|
|
16
|
-
*/
|
|
17
|
-
constructor(name: string, type: ComponentType, settings: EncoderSetup);
|
|
18
|
-
name: string;
|
|
19
|
-
type: ComponentType;
|
|
20
|
-
alphabet: string;
|
|
21
|
-
contactCount: number;
|
|
22
|
-
/** @type {{[name: string]: Listener}} */
|
|
23
|
-
listeners: {
|
|
24
|
-
[name: string]: Listener;
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* given a connector number, normalize it to be between 0 and 25 inclusive.
|
|
28
|
-
*
|
|
29
|
-
* @param {Number} connector the connector being normalized
|
|
30
|
-
*
|
|
31
|
-
* @returns {Number} value between 0 and 25
|
|
32
|
-
*/
|
|
33
|
-
normalize(connector: number): number;
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @param {string} letter
|
|
37
|
-
*
|
|
38
|
-
* @returns {boolean}
|
|
39
|
-
*/
|
|
40
|
-
verifyLetter(letter: string): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* Call this method to convert a letter to a connector value
|
|
43
|
-
*
|
|
44
|
-
* @param {string} letter
|
|
45
|
-
* @returns {number | undefined}
|
|
46
|
-
*/
|
|
47
|
-
letterToConnector(letter: string): number | undefined;
|
|
48
|
-
/**
|
|
49
|
-
* Call this method to turn a connector to a letter value
|
|
50
|
-
*
|
|
51
|
-
* @param {number} connector
|
|
52
|
-
* @returns {string | undefined}
|
|
53
|
-
*/
|
|
54
|
-
connectorToLetter(connector: number): string | undefined;
|
|
55
|
-
/**
|
|
56
|
-
* Given an alphabetic connection map, convert that into an array of
|
|
57
|
-
* numbers. The index into the array or string is the input connector, and
|
|
58
|
-
* the value at that position is the output connector
|
|
59
|
-
*
|
|
60
|
-
* @param {String} map connections map.
|
|
61
|
-
* @returns {Array.<Number>} the numerical map
|
|
62
|
-
*/
|
|
63
|
-
makeMap(map: string): Array<number>;
|
|
64
|
-
/**
|
|
65
|
-
* given an existing connection map from input to out put, create a new map
|
|
66
|
-
* that has the connections going in the other direction, output to input.
|
|
67
|
-
*
|
|
68
|
-
* @param {Array.<Number>} map connection map
|
|
69
|
-
* @returns {Array.<Number>} the reversed map
|
|
70
|
-
*/
|
|
71
|
-
makeReverseMap(map: Array<number>): Array<number>;
|
|
72
|
-
/**
|
|
73
|
-
* Call this method to convert the input connector number to the output in
|
|
74
|
-
* the given direction The default encode method just passes the input value
|
|
75
|
-
* through
|
|
76
|
-
*
|
|
77
|
-
* @param {Direction} _direction either right for moving towards the reflector
|
|
78
|
-
* or left if moving back
|
|
79
|
-
* @param {Number} input the specific connection receiving an input
|
|
80
|
-
*
|
|
81
|
-
* @returns {Number} The translated output connector number
|
|
82
|
-
*/
|
|
83
|
-
encode(_direction: Direction, input: number): number;
|
|
84
|
-
/**
|
|
85
|
-
*
|
|
86
|
-
* @param {number | string} input
|
|
87
|
-
* @param {Direction} direction
|
|
88
|
-
*/
|
|
89
|
-
fireInput(input: number | string, direction: Direction): void;
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* @param {number | string} output
|
|
93
|
-
* @param {Direction} direction
|
|
94
|
-
*/
|
|
95
|
-
fireOutput(output: number | string, direction: Direction): void;
|
|
96
|
-
/**
|
|
97
|
-
*
|
|
98
|
-
* @param {number | string} input
|
|
99
|
-
* @param {number | string} output
|
|
100
|
-
* @param {Direction} direction
|
|
101
|
-
*/
|
|
102
|
-
fireTranslate(input: number | string, output: number | string, direction: Direction): void;
|
|
103
|
-
/**
|
|
104
|
-
*
|
|
105
|
-
* @param {number | string} input
|
|
106
|
-
* @param {number | string} output
|
|
107
|
-
* @param {Direction} direction
|
|
108
|
-
*/
|
|
109
|
-
fireEncodeSet(input: number | string, output: number | string, direction: Direction): void;
|
|
110
|
-
/**
|
|
111
|
-
* Call this method to add a function to be called when important events
|
|
112
|
-
* happen to a component. The name can be used to later remove the listener
|
|
113
|
-
*
|
|
114
|
-
* @param {string} name - the name of the listener
|
|
115
|
-
* @param {Listener} cb - the function to be called.
|
|
116
|
-
*/
|
|
117
|
-
listen(name: string, cb: Listener): void;
|
|
118
|
-
/**
|
|
119
|
-
* Call this method to remove a listener
|
|
120
|
-
*
|
|
121
|
-
* @param {string} name - the name of the listener
|
|
122
|
-
*/
|
|
123
|
-
unlisten(name: string): void;
|
|
124
|
-
/**
|
|
125
|
-
* Call this method to call any event listeners
|
|
126
|
-
*
|
|
127
|
-
* @param {EventName} event - the event being fired
|
|
128
|
-
* @param {String} name - the name of the component firing the event
|
|
129
|
-
* @param {EventData} data - the event data
|
|
130
|
-
*/
|
|
131
|
-
fire(event: EventName, name: string, data: EventData): void;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
declare module "enigma/EntryDisc" {
|
|
135
|
-
/**
|
|
136
|
-
* This is the class for an entry disc. Entry discs are fixed disks of connector
|
|
137
|
-
* pins.
|
|
138
|
-
*/
|
|
139
|
-
export default class EntryDisc extends Encoder {
|
|
140
|
-
/**
|
|
141
|
-
* Constructor for the entry disc.
|
|
142
|
-
*
|
|
143
|
-
* @param {String} name the name of this entry disc
|
|
144
|
-
* @param {EncoderSetup} settings contains the alphabet being used, and the map
|
|
145
|
-
* between input and output contacts
|
|
146
|
-
*/
|
|
147
|
-
constructor(name: string, settings: EncoderSetup);
|
|
148
|
-
rightMap: number[];
|
|
149
|
-
leftMap: number[];
|
|
150
|
-
}
|
|
151
|
-
import Encoder from "enigma/Encoder";
|
|
152
|
-
}
|
|
153
|
-
declare module "enigma/PlugBoard" {
|
|
154
|
-
/**
|
|
155
|
-
* This class represents the plugboard. There is only one type of plugboard
|
|
156
|
-
*/
|
|
157
|
-
export default class PlugBoard extends Encoder {
|
|
158
|
-
/**
|
|
159
|
-
* Constructor for the plugboard.
|
|
160
|
-
*
|
|
161
|
-
* @param {String} name the name for the plugboard, defaults to 'plugboard'
|
|
162
|
-
* @param {EncoderSetup} [settings] the settings for the plugboard. Only needed if
|
|
163
|
-
* using an alternate alphabet
|
|
164
|
-
*/
|
|
165
|
-
constructor(name?: string, settings?: EncoderSetup);
|
|
166
|
-
map: string;
|
|
167
|
-
rightMap: any[];
|
|
168
|
-
leftMap: any[];
|
|
169
|
-
plugs: string;
|
|
170
|
-
/**
|
|
171
|
-
* Call this method to configure the plug board. This will be used to
|
|
172
|
-
* provide the plug connections
|
|
173
|
-
*
|
|
174
|
-
* @param {Plugs} plugs the configuration options for the plug
|
|
175
|
-
* board
|
|
176
|
-
*/
|
|
177
|
-
configure(plugs?: Plugs): void;
|
|
178
|
-
}
|
|
179
|
-
import Encoder from "enigma/Encoder";
|
|
180
|
-
}
|
|
181
|
-
declare module "enigma/Rotor" {
|
|
182
|
-
/**
|
|
183
|
-
* Create an instance of this class to construct a Rotor object. The Rotor class
|
|
184
|
-
* encapsulates many of the peculiar behaviors of the Enigma. All connector
|
|
185
|
-
* values here are specified in physical space.
|
|
186
|
-
*/
|
|
187
|
-
export default class Rotor extends Encoder {
|
|
188
|
-
/**
|
|
189
|
-
* This is the constructor for the rotor.
|
|
190
|
-
*
|
|
191
|
-
* @param {String} name the name of the rotor; under normal circumstances
|
|
192
|
-
* this will be the string 'rotor-' plus the standard name for the rotor,
|
|
193
|
-
* for example 'rotor-IV'
|
|
194
|
-
* @param {RotorSetup} settings an object that contains the various options that
|
|
195
|
-
* define the the rotor and how it is configured.
|
|
196
|
-
*/
|
|
197
|
-
constructor(name: string, settings: RotorSetup);
|
|
198
|
-
map: any[];
|
|
199
|
-
rightMap: number[];
|
|
200
|
-
leftMap: number[];
|
|
201
|
-
length: number;
|
|
202
|
-
ringOffset: number;
|
|
203
|
-
turnoverLookup: number[];
|
|
204
|
-
offset: number;
|
|
205
|
-
fixed: boolean;
|
|
206
|
-
turnovers: string;
|
|
207
|
-
_turnovers: Set<number>;
|
|
208
|
-
/**
|
|
209
|
-
* Call this method to select the initial rotation of the rotor. This is a
|
|
210
|
-
* letter offset from the logical 0 connector. The initial rotation will
|
|
211
|
-
* also take into account the ring setting
|
|
212
|
-
*
|
|
213
|
-
* @param {String} connector This is a letter value that corresponds to what
|
|
214
|
-
* would appear in the rotation window. This value will be adjusted for the
|
|
215
|
-
* ring setting.
|
|
216
|
-
*/
|
|
217
|
-
setStartPosition(connector: string): void;
|
|
218
|
-
/**
|
|
219
|
-
* Call this method to step the rotor
|
|
220
|
-
*
|
|
221
|
-
* @returns {Boolean} true if the next rotor should be stepped
|
|
222
|
-
*/
|
|
223
|
-
step(): boolean;
|
|
224
|
-
/**
|
|
225
|
-
* Call this method to see if the next step on this rotor will lead to
|
|
226
|
-
* turnover. The Enigma class will call this on the middle rotor to handle
|
|
227
|
-
* double stepping.
|
|
228
|
-
*
|
|
229
|
-
* @returns true if this rotor will turnover on the next step
|
|
230
|
-
*/
|
|
231
|
-
willTurnover(): boolean;
|
|
232
|
-
shouldTurnover(): boolean;
|
|
233
|
-
/**
|
|
234
|
-
* Call this method to find whether this is a fixed rotor. This is used for
|
|
235
|
-
* the non stepping rotors--beta and gamma--that are used in the M4
|
|
236
|
-
* @returns
|
|
237
|
-
*/
|
|
238
|
-
isFixed(): boolean;
|
|
239
|
-
}
|
|
240
|
-
import Encoder from "enigma/Encoder";
|
|
241
|
-
}
|
|
242
|
-
declare module "enigma/Reflector" {
|
|
243
|
-
/**
|
|
244
|
-
* Make in instance of this class to construct a reflector
|
|
245
|
-
*/
|
|
246
|
-
export default class Reflector extends Encoder {
|
|
247
|
-
/**
|
|
248
|
-
* constructor for the reflector class.
|
|
249
|
-
*
|
|
250
|
-
* @param {String} name the name of the reflector instance
|
|
251
|
-
* @param {EncoderSetup} settings The definition of the reflector
|
|
252
|
-
*/
|
|
253
|
-
constructor(name: string, settings: EncoderSetup);
|
|
254
|
-
map: number[];
|
|
255
|
-
}
|
|
256
|
-
import Encoder from "enigma/Encoder";
|
|
257
|
-
}
|
|
258
|
-
declare module "enigma/Inventory" {
|
|
259
|
-
const _default: Inventory;
|
|
260
|
-
export default _default;
|
|
261
|
-
/**
|
|
262
|
-
* This is the class used to manage the standard inventory of components. An
|
|
263
|
-
* instance of this class is exported as the default of this module
|
|
264
|
-
*/
|
|
265
|
-
class Inventory {
|
|
266
|
-
entryDiscs: {};
|
|
267
|
-
/** @type {{[name: string]: RouterInventorySpec}}*/
|
|
268
|
-
rotors: {
|
|
269
|
-
[name: string]: RouterInventorySpec;
|
|
270
|
-
};
|
|
271
|
-
reflectors: {};
|
|
272
|
-
/**
|
|
273
|
-
* Call this method to add a new Rotor type to the inventory.
|
|
274
|
-
*
|
|
275
|
-
* @param {String} name the name of the rotor being added. This name will be
|
|
276
|
-
* used when specifying the rotors to use for the Enigma configuration.
|
|
277
|
-
* @param {String} map a string specifying the connector mapping. The index
|
|
278
|
-
* of the string is the logical coordinate of the connector, the character
|
|
279
|
-
* at that index is the output connector. To be exact, it would be the
|
|
280
|
-
* position of that character in the given alphabet. So, in the map '
|
|
281
|
-
* EKMFLGDQVZNTOWYHXUSPAIBRCJ', input connector 0 would map to output
|
|
282
|
-
* connector 4 and input connector 1 would map to output connector 10.
|
|
283
|
-
* Remember that the connectors are numbered starting at 0.
|
|
284
|
-
* @param {String} turnovers this is a string of characters representing the
|
|
285
|
-
* turnover locations on the disk. These letter would be the value shown in
|
|
286
|
-
* the window to during turnover. In Rotor I this is 'Q' in rotors VI, VII,
|
|
287
|
-
* and VIII there are two turnover locations, 'M' and 'Z'. Pass an empty
|
|
288
|
-
* string if this is a fixed rotor
|
|
289
|
-
*/
|
|
290
|
-
addRotor(name: string, map: string, turnovers: string): void;
|
|
291
|
-
/**
|
|
292
|
-
* Call this method to add a new reflector definition.
|
|
293
|
-
*
|
|
294
|
-
* @param {String} name this is the name that will be used to reference this
|
|
295
|
-
* reflector when constructing an Enigma class.
|
|
296
|
-
* @param {String} map the mapping between connectors. this uses the same
|
|
297
|
-
* format used in the addRotor method
|
|
298
|
-
*/
|
|
299
|
-
addReflector(name: string, map: string): void;
|
|
300
|
-
/**
|
|
301
|
-
* Call this method to add a new entry disc. There was only one used in the
|
|
302
|
-
* standard military models, but there were other versions that defined it
|
|
303
|
-
* differently.
|
|
304
|
-
*
|
|
305
|
-
* @param {*} name this is the name that will be used to reference this
|
|
306
|
-
* entry disc when constructing an Enigma class.
|
|
307
|
-
* @param {*} map the mapping between connectors. this uses the same format
|
|
308
|
-
* used in the addRotor method
|
|
309
|
-
*/
|
|
310
|
-
addEntryDisc(name: any, map: any): void;
|
|
311
|
-
/**
|
|
312
|
-
* Call this method to get the setup for a defined rotor.
|
|
313
|
-
*
|
|
314
|
-
* @param {String} name the name of the rotor as it was added to the
|
|
315
|
-
* inventory.
|
|
316
|
-
*
|
|
317
|
-
* @returns {Object} the rotor definition
|
|
318
|
-
* @property {String} map the connection map for the rotor
|
|
319
|
-
* @property {String} turnovers the locations where turnovers happen
|
|
320
|
-
*/
|
|
321
|
-
getRotor(name: string): any;
|
|
322
|
-
/**
|
|
323
|
-
* Call this method to get the setup for a defined reflector.
|
|
324
|
-
*
|
|
325
|
-
* @param {String} name the name of the reflector as it was added to the
|
|
326
|
-
* inventory.
|
|
327
|
-
* @returns {Object} the reflector definition
|
|
328
|
-
* @property {String} the connection map for the reflector
|
|
329
|
-
*/
|
|
330
|
-
getReflector(name: string): any;
|
|
331
|
-
/**
|
|
332
|
-
* Call this method to get the setup for a defined entry disc.
|
|
333
|
-
*
|
|
334
|
-
* @param {String} name the name of the entry disc as it was added to the
|
|
335
|
-
* inventory.
|
|
336
|
-
* @returns {Object} the entry disc definition
|
|
337
|
-
* @property {String} the connection map for the entry disc
|
|
338
|
-
*/
|
|
339
|
-
getEntryDisc(name: string): any;
|
|
340
|
-
/**
|
|
341
|
-
* Call this method to get the names of all the rotors in the inventory
|
|
342
|
-
*
|
|
343
|
-
* @param {boolean} [fixed] - if specified it returns only the names of
|
|
344
|
-
* routers filtered on if they are fixed or not, otherwise it returns all
|
|
345
|
-
*
|
|
346
|
-
* @returns {string[]} the names of the rotors
|
|
347
|
-
*/
|
|
348
|
-
getRotorNames(fixed?: boolean): string[];
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
declare module "enigma/Enigma" {
|
|
352
|
-
/**
|
|
353
|
-
* Construct this class to get a new instance of the Enigma. Many of the
|
|
354
|
-
* parameters to the constructor and the config method reference the names of
|
|
355
|
-
* standard Enigma parts. These are retrieved from the Inventory instance
|
|
356
|
-
*/
|
|
357
|
-
export default class Enigma extends Encoder {
|
|
358
|
-
/**
|
|
359
|
-
* The constructor for the Enigma. This represents the unconfigurable
|
|
360
|
-
* settings of the device.
|
|
361
|
-
*
|
|
362
|
-
* @param {string} name
|
|
363
|
-
* @param {EnigmaSetup} settings
|
|
364
|
-
*/
|
|
365
|
-
constructor(name: string, settings: EnigmaSetup);
|
|
366
|
-
plugboard: PlugBoard;
|
|
367
|
-
entryDisc: EntryDisc;
|
|
368
|
-
reflector: Reflector;
|
|
369
|
-
length: number;
|
|
370
|
-
/** @type {Rotor[]} */
|
|
371
|
-
_rotors: Rotor[];
|
|
372
|
-
/** @type {{[rotor: number]: boolean}} */
|
|
373
|
-
pending: {
|
|
374
|
-
[rotor: number]: boolean;
|
|
375
|
-
};
|
|
376
|
-
/** @type {Encoder[]} */
|
|
377
|
-
encoders: Encoder[];
|
|
378
|
-
/**@type {SimplifiedConfiguration & {reflector: string}} */
|
|
379
|
-
_configuration: SimplifiedConfiguration & {
|
|
380
|
-
reflector: string;
|
|
381
|
-
};
|
|
382
|
-
/**
|
|
383
|
-
* the configured rotors
|
|
384
|
-
*
|
|
385
|
-
* @return {Rotor[]}
|
|
386
|
-
*/
|
|
387
|
-
get rotors(): Rotor[];
|
|
388
|
-
/**
|
|
389
|
-
* @returns {SimplifiedConfiguration & {reflector: string}}
|
|
390
|
-
*/
|
|
391
|
-
get configuration(): SimplifiedConfiguration & {
|
|
392
|
-
reflector: string;
|
|
393
|
-
};
|
|
394
|
-
/**
|
|
395
|
-
* Configure the Enigma for encoding.
|
|
396
|
-
*
|
|
397
|
-
* @param {EnigmaConfiguration} settings - the configuration of the Enigma.
|
|
398
|
-
* These settings represent the aspects of the Enigma that can can change for daily
|
|
399
|
-
* configuration.
|
|
400
|
-
*/
|
|
401
|
-
configure(settings: EnigmaConfiguration): void;
|
|
402
|
-
/**
|
|
403
|
-
* Call this method to "step" the rotors one time. This method will manage the
|
|
404
|
-
* stepping between all rotors
|
|
405
|
-
*/
|
|
406
|
-
step(): void;
|
|
407
|
-
/**
|
|
408
|
-
* Call this method to set the starting rotation for the messages to encrypt
|
|
409
|
-
*
|
|
410
|
-
* @param {number[]|string} setup - length of the string or the array
|
|
411
|
-
* should match the number of rotors and are given left to right. If start
|
|
412
|
-
* is a string then the letters of the string specify the start value seen
|
|
413
|
-
* in the window for the corresponding rotor. If it is an array then each
|
|
414
|
-
* number will be the one-based rotation.
|
|
415
|
-
*/
|
|
416
|
-
setStart(setup: number[] | string): void;
|
|
417
|
-
/**
|
|
418
|
-
* Call this method to simulate a keypress on the Enigma. This will output
|
|
419
|
-
* the encoded letter
|
|
420
|
-
*
|
|
421
|
-
* @param {String} letter the key pressed
|
|
422
|
-
* @returns {String | undefined} the encoded letter
|
|
423
|
-
*/
|
|
424
|
-
keyPress(letter: string): string | undefined;
|
|
425
|
-
/**
|
|
426
|
-
* Call this shortcut method to encode a whole string
|
|
427
|
-
*
|
|
428
|
-
* @param {String} start the starting position for the rotors
|
|
429
|
-
* @param {String} text the text to encode
|
|
430
|
-
*
|
|
431
|
-
* @returns {String} the encoded string.
|
|
432
|
-
*/
|
|
433
|
-
translate(start: string, text: string): string;
|
|
434
|
-
}
|
|
435
|
-
import Encoder from "enigma/Encoder";
|
|
436
|
-
import PlugBoard from "enigma/PlugBoard";
|
|
437
|
-
import EntryDisc from "enigma/EntryDisc";
|
|
438
|
-
import Reflector from "enigma/Reflector";
|
|
439
|
-
import Rotor from "enigma/Rotor";
|
|
440
|
-
}
|
|
441
|
-
declare module "enigma/standardInventory" {
|
|
442
|
-
export namespace entryDiscDefinitions {
|
|
443
|
-
let _default: string;
|
|
444
|
-
export { _default as default };
|
|
445
|
-
}
|
|
446
|
-
export namespace rotorDefinitions {
|
|
447
|
-
namespace I {
|
|
448
|
-
let map: string;
|
|
449
|
-
let turnovers: string;
|
|
450
|
-
}
|
|
451
|
-
namespace II {
|
|
452
|
-
let map_1: string;
|
|
453
|
-
export { map_1 as map };
|
|
454
|
-
let turnovers_1: string;
|
|
455
|
-
export { turnovers_1 as turnovers };
|
|
456
|
-
}
|
|
457
|
-
namespace III {
|
|
458
|
-
let map_2: string;
|
|
459
|
-
export { map_2 as map };
|
|
460
|
-
let turnovers_2: string;
|
|
461
|
-
export { turnovers_2 as turnovers };
|
|
462
|
-
}
|
|
463
|
-
namespace IV {
|
|
464
|
-
let map_3: string;
|
|
465
|
-
export { map_3 as map };
|
|
466
|
-
let turnovers_3: string;
|
|
467
|
-
export { turnovers_3 as turnovers };
|
|
468
|
-
}
|
|
469
|
-
namespace V {
|
|
470
|
-
let map_4: string;
|
|
471
|
-
export { map_4 as map };
|
|
472
|
-
let turnovers_4: string;
|
|
473
|
-
export { turnovers_4 as turnovers };
|
|
474
|
-
}
|
|
475
|
-
namespace VI {
|
|
476
|
-
let map_5: string;
|
|
477
|
-
export { map_5 as map };
|
|
478
|
-
let turnovers_5: string;
|
|
479
|
-
export { turnovers_5 as turnovers };
|
|
480
|
-
}
|
|
481
|
-
namespace VII {
|
|
482
|
-
let map_6: string;
|
|
483
|
-
export { map_6 as map };
|
|
484
|
-
let turnovers_6: string;
|
|
485
|
-
export { turnovers_6 as turnovers };
|
|
486
|
-
}
|
|
487
|
-
namespace VIII {
|
|
488
|
-
let map_7: string;
|
|
489
|
-
export { map_7 as map };
|
|
490
|
-
let turnovers_7: string;
|
|
491
|
-
export { turnovers_7 as turnovers };
|
|
492
|
-
}
|
|
493
|
-
namespace Beta {
|
|
494
|
-
let map_8: string;
|
|
495
|
-
export { map_8 as map };
|
|
496
|
-
let turnovers_8: string;
|
|
497
|
-
export { turnovers_8 as turnovers };
|
|
498
|
-
}
|
|
499
|
-
namespace Gamma {
|
|
500
|
-
let map_9: string;
|
|
501
|
-
export { map_9 as map };
|
|
502
|
-
let turnovers_9: string;
|
|
503
|
-
export { turnovers_9 as turnovers };
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
export const reflectorDefinitions: {
|
|
507
|
-
A: string;
|
|
508
|
-
B: string;
|
|
509
|
-
C: string;
|
|
510
|
-
'Thin-B': string;
|
|
511
|
-
'Thin-C': string;
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
declare module "enigma/index" {
|
|
515
|
-
export { default as Enigma } from "./Enigma.js";
|
|
516
|
-
export { default as EntryDisc } from "./EntryDisc.js";
|
|
517
|
-
export { default as inventory } from "./Inventory.js";
|
|
518
|
-
export { default as PlugBoard } from "./PlugBoard.js";
|
|
519
|
-
export { default as Reflector } from "./Rotor.js";
|
|
520
|
-
}
|
|
521
|
-
declare module "generator/hamlet" {
|
|
522
|
-
export default sentences;
|
|
523
|
-
const sentences: string[];
|
|
524
|
-
}
|
|
525
|
-
declare module "utils/Random" {
|
|
526
|
-
const _default: Random;
|
|
527
|
-
export default _default;
|
|
528
|
-
/**
|
|
529
|
-
* This class implements a pseudorandom number generator that can be given a
|
|
530
|
-
* seed to produce a consistent sequence of numbers. This algorithm is
|
|
531
|
-
* inappropriate for real cryptographic purposes, but allows the production of
|
|
532
|
-
* output that can be consistently reproduced.
|
|
533
|
-
*
|
|
534
|
-
* This algorithm was stolen from the product Delphi.
|
|
535
|
-
*/
|
|
536
|
-
class Random {
|
|
537
|
-
randSeed: number;
|
|
538
|
-
/**
|
|
539
|
-
* Call this method to set the seed value for the randomizer. The initial value
|
|
540
|
-
* will be the current time in milliseconds.
|
|
541
|
-
*
|
|
542
|
-
* @param {Number} value for the seed,
|
|
543
|
-
*/
|
|
544
|
-
randomize(value: number): void;
|
|
545
|
-
/**
|
|
546
|
-
* Call this method to get a random number. If passed a value, the return
|
|
547
|
-
* will be an integer between 0 and that number - 1. without it will be a
|
|
548
|
-
* decimal value between 0 and < 1.
|
|
549
|
-
*
|
|
550
|
-
* @param {Number} [limit] if passed the upper boundary of the integer - 1
|
|
551
|
-
*
|
|
552
|
-
* @returns {Number} the randomized value as either an integer or a decimal
|
|
553
|
-
* value depending on how it was called.
|
|
554
|
-
*/
|
|
555
|
-
random(limit?: number): number;
|
|
556
|
-
/**
|
|
557
|
-
* Generate a random number using a bell curve. The curve is created using
|
|
558
|
-
* the analogy of dice. For example, a random number built with two six
|
|
559
|
-
* sided dice will have the peak of the curve at 7 with 2 and 12 being at
|
|
560
|
-
* the bottom.
|
|
561
|
-
*
|
|
562
|
-
* @param {number} dice - how many random numbers to pick
|
|
563
|
-
* @param {number} faces - the range, from 1 - faces, of the number
|
|
564
|
-
* @param {boolean} [zeroBased] - if true, the random range for each die will be from 0 - faces-1
|
|
565
|
-
*
|
|
566
|
-
* @return {number} the random number
|
|
567
|
-
*/
|
|
568
|
-
randomCurve(dice: number, faces: number, zeroBased?: boolean): number;
|
|
569
|
-
/**
|
|
570
|
-
* call this method to pick a random number from an array and remove it
|
|
571
|
-
*
|
|
572
|
-
* @template T
|
|
573
|
-
* @param {T[]} list the array of items to choose from
|
|
574
|
-
*
|
|
575
|
-
* @returns {T} the chosen item
|
|
576
|
-
*/
|
|
577
|
-
pickOne<T>(list: T[]): T;
|
|
578
|
-
/**
|
|
579
|
-
* Call this method to pick two items from a given list. The items are
|
|
580
|
-
* removed from the array. If the array is less than two items then it
|
|
581
|
-
* will return either an empty array or an array with one element.
|
|
582
|
-
*
|
|
583
|
-
* @template T
|
|
584
|
-
*
|
|
585
|
-
* @param {T[]} list the array of items to choose
|
|
586
|
-
* @returns {T[]} the two chosen items
|
|
587
|
-
*/
|
|
588
|
-
pickPair<T>(list: T[]): T[];
|
|
589
|
-
/**
|
|
590
|
-
* Call this method to choose a given number of items from a list. The items
|
|
591
|
-
* are removed.
|
|
592
|
-
*
|
|
593
|
-
* @template T
|
|
594
|
-
*
|
|
595
|
-
* @param {Number} count the number of items to pick
|
|
596
|
-
* @param {T[]} list the list of items to choose from
|
|
597
|
-
*
|
|
598
|
-
* @returns {T[]} the chosen items
|
|
599
|
-
*/
|
|
600
|
-
pick<T>(count: number, list: T[]): T[];
|
|
601
|
-
/**
|
|
602
|
-
* Call this method to randomly pick a set of item pairs. The items
|
|
603
|
-
* will be removed from the list.
|
|
604
|
-
*
|
|
605
|
-
* @template T
|
|
606
|
-
* @param {Number} count the number of pairs to pick
|
|
607
|
-
* @param {T[]} list the list of items to choose from
|
|
608
|
-
*,
|
|
609
|
-
* @returns {T[][]}} the item pairs chosen. Each pair is an array of
|
|
610
|
-
* two items from the list
|
|
611
|
-
*/
|
|
612
|
-
pickPairs<T>(count: number, list: T[]): T[][];
|
|
613
|
-
/**
|
|
614
|
-
* Call this method to chose a random item from a list. The item is not
|
|
615
|
-
* removed.
|
|
616
|
-
*
|
|
617
|
-
* @template T
|
|
618
|
-
*
|
|
619
|
-
* @param {T[]} list the list of items to choose from
|
|
620
|
-
* @returns {T} the chosen item
|
|
621
|
-
*/
|
|
622
|
-
chooseOne<T>(list: T[]): T;
|
|
623
|
-
/**
|
|
624
|
-
* Call this method to pick a pair of items from the given list. The items
|
|
625
|
-
* are guaranteed to be unique.
|
|
626
|
-
*
|
|
627
|
-
* @template T
|
|
628
|
-
*
|
|
629
|
-
* @param {T[]} list - the list of items
|
|
630
|
-
* @returns {T[]}
|
|
631
|
-
*/
|
|
632
|
-
choosePair<T>(list: T[]): T[];
|
|
633
|
-
/**
|
|
634
|
-
* Call this method to return a random list of contiguous items from the
|
|
635
|
-
* given list. The items are not removed.
|
|
636
|
-
*
|
|
637
|
-
* @template T
|
|
638
|
-
* @param {number} count
|
|
639
|
-
* @param {T[]} list
|
|
640
|
-
*
|
|
641
|
-
* return {T[]}
|
|
642
|
-
*/
|
|
643
|
-
chooseRange<T>(count: number, list: T[]): string;
|
|
644
|
-
/**
|
|
645
|
-
* Call this method to randomly pick a subset of items from a list. The
|
|
646
|
-
* items are not removed.
|
|
647
|
-
*
|
|
648
|
-
* @template T
|
|
649
|
-
*
|
|
650
|
-
* @param {Number} count the number of items to choose
|
|
651
|
-
* @param {T[]} list the list of items to choose from
|
|
652
|
-
*
|
|
653
|
-
* @returns {T[]} the list of items chosen
|
|
654
|
-
*/
|
|
655
|
-
choose<T>(count: number, list: T[]): T[];
|
|
656
|
-
}
|
|
657
|
-
}
|
|
658
|
-
declare module "generator/Generator" {
|
|
659
|
-
/**
|
|
660
|
-
* Use this class to generate random enigma configurations and messages. The
|
|
661
|
-
* methods in this class all the use the `Random` object, which can be seeded to
|
|
662
|
-
* produce a reproducible output
|
|
663
|
-
*/
|
|
664
|
-
export default class Generator {
|
|
665
|
-
/**
|
|
666
|
-
* Call this method to turn a string into valid characters for encryption,
|
|
667
|
-
* which is just the letters A-Z.
|
|
668
|
-
*
|
|
669
|
-
* @param {String} text the original text
|
|
670
|
-
* @returns {String} the text that has been normalized to what the Enigma
|
|
671
|
-
* can process
|
|
672
|
-
*/
|
|
673
|
-
cleanMessage(text: string): string;
|
|
674
|
-
/**
|
|
675
|
-
* Call this method to break a string into groups of five letters with a
|
|
676
|
-
* space between them.
|
|
677
|
-
*
|
|
678
|
-
* @param {string} text - the original text
|
|
679
|
-
* @param {number} [size] - the size of the text groups, defaults to 5
|
|
680
|
-
*
|
|
681
|
-
* @returns {string} the segmented string
|
|
682
|
-
*/
|
|
683
|
-
groupText(text: string, size?: number): string;
|
|
684
|
-
/**
|
|
685
|
-
* Call this method to generate the given number of sentences. The sentences
|
|
686
|
-
* are pulled from the text of Hamlet.
|
|
687
|
-
*
|
|
688
|
-
* @param {Number} count the number of sentences
|
|
689
|
-
* @returns {String} the sentences separated by a ' ';
|
|
690
|
-
*/
|
|
691
|
-
generateSentences(count: number): string;
|
|
692
|
-
/**
|
|
693
|
-
* Call this method to get the possible setup and configuration options for
|
|
694
|
-
* the given model
|
|
695
|
-
*
|
|
696
|
-
* @param {Model} model
|
|
697
|
-
*
|
|
698
|
-
* @returns {ModelOptions}
|
|
699
|
-
*/
|
|
700
|
-
getModelOptions(model: Model): ModelOptions;
|
|
701
|
-
/**
|
|
702
|
-
* Call this method to generate a random Enigma configuration
|
|
703
|
-
*
|
|
704
|
-
* @param {GeneratorSetup} [setup] options for settings
|
|
705
|
-
|
|
706
|
-
* @returns {SimplifiedConfiguration} the Enigma settings.
|
|
707
|
-
*/
|
|
708
|
-
generateEnigmaConfiguration(setup?: GeneratorSetup): SimplifiedConfiguration;
|
|
709
|
-
/**
|
|
710
|
-
*
|
|
711
|
-
* @param {string[]} [reflectors] if given, specifies and alternate list of
|
|
712
|
-
* reflectors. Defaults to ['A', 'B', 'C'];
|
|
713
|
-
*/
|
|
714
|
-
createRandomEnigma(model?: string, reflectors?: string[]): Enigma;
|
|
715
|
-
/**
|
|
716
|
-
* Call this method to generate a random message text encoded with the given
|
|
717
|
-
* Enigma. The random text will be a few sentences from Hamlet.
|
|
718
|
-
*
|
|
719
|
-
* @param {Enigma} enigma
|
|
720
|
-
*
|
|
721
|
-
* @returns {GeneratedMessage} details of the generated text
|
|
722
|
-
*/
|
|
723
|
-
generateMessage(enigma: Enigma): GeneratedMessage;
|
|
724
|
-
}
|
|
725
|
-
import Enigma from "enigma/Enigma";
|
|
726
|
-
}
|
|
727
|
-
declare module "generator/CodeBook" {
|
|
728
|
-
/**
|
|
729
|
-
* Use this class to generate Enigma key sheets and messages using it. The
|
|
730
|
-
* procedures used were derived from the information at
|
|
731
|
-
* [Enigma Message Procedures](https://www.ciphermachinesandcryptology.com/en/enigmaproc.htm)
|
|
732
|
-
*/
|
|
733
|
-
export default class CodeBook {
|
|
734
|
-
/**
|
|
735
|
-
* Constructor for the `CodeBook` class.
|
|
736
|
-
* @param {Enigma} enigma - all encryption will be done using this configured Enigma
|
|
737
|
-
*/
|
|
738
|
-
constructor(enigma: Enigma);
|
|
739
|
-
enigma: Enigma;
|
|
740
|
-
indicators: {};
|
|
741
|
-
generator: Generator;
|
|
742
|
-
/**
|
|
743
|
-
* Call this method to provide a new configuration to the enigma
|
|
744
|
-
*
|
|
745
|
-
* @param {SimplifiedConfiguration} config
|
|
746
|
-
*/
|
|
747
|
-
configure(config: SimplifiedConfiguration): void;
|
|
748
|
-
reset(): void;
|
|
749
|
-
/**
|
|
750
|
-
* Call this method to create a three letter string as an identifier for a
|
|
751
|
-
* a day in a key sheet
|
|
752
|
-
*
|
|
753
|
-
* @returns {String} the string
|
|
754
|
-
*/
|
|
755
|
-
makeIndicator(): string;
|
|
756
|
-
/**
|
|
757
|
-
* Call this method to create a single days configuration for a key sheet.
|
|
758
|
-
* This an Enigma configuration plus the other metadata.
|
|
759
|
-
*
|
|
760
|
-
* @param {number} day the day of the month
|
|
761
|
-
*
|
|
762
|
-
* @returns {KeySheetLine} One line of a key sheet
|
|
763
|
-
*/
|
|
764
|
-
generateDay(day: number): KeySheetLine;
|
|
765
|
-
/**
|
|
766
|
-
* Call this method to construct a key sheet for the given number of days
|
|
767
|
-
*
|
|
768
|
-
* @param {Number} days the number of days on the key sheet
|
|
769
|
-
* @returns {KeySheetLine[]} the array of day objects
|
|
770
|
-
*/
|
|
771
|
-
generateKeySheet(days: number): KeySheetLine[];
|
|
772
|
-
/**
|
|
773
|
-
* Call this method to process one sub-message from a longer message. This is
|
|
774
|
-
* part of code to generate a message as the Enigma would have been used.
|
|
775
|
-
*
|
|
776
|
-
* @param {string[]} indicators the three letter code that can be sent to
|
|
777
|
-
* reference the configuration of the Enigma. These will be used to cross
|
|
778
|
-
* reference the message to the machine configuration on the key sheet
|
|
779
|
-
* @param {String} text the cleaned up string to be encoded
|
|
780
|
-
*
|
|
781
|
-
* @returns {MessagePart} the encoded message segment
|
|
782
|
-
*/
|
|
783
|
-
encodeOnePart(indicators: string[], text: string): MessagePart;
|
|
784
|
-
/**
|
|
785
|
-
* Call this method to generate a full message based on the data in a key
|
|
786
|
-
* sheet. The message constructed reflects an actual message as the Enigma
|
|
787
|
-
* was really used. An individual message cannot be more than 250
|
|
788
|
-
* characters, so longer messages are broken into multiple parts, each one
|
|
789
|
-
* encoded with a unique key
|
|
790
|
-
*
|
|
791
|
-
* @param {KeySheetLine[]} sheet a key sheet generated using generateKeySheet
|
|
792
|
-
* @param {number} [dayIdx] - if provided, specifies the day of the month for the message
|
|
793
|
-
* @param {string} [text] - if provided, this is the text of the message to generate
|
|
794
|
-
* @returns {KeyBookMessage} a list of encoded sub messages
|
|
795
|
-
*/
|
|
796
|
-
generateMessage(sheet: KeySheetLine[], dayIdx?: number, text?: string): KeyBookMessage;
|
|
797
|
-
/**
|
|
798
|
-
* Call this method to generate a given number of messages based on a
|
|
799
|
-
* generated key sheet
|
|
800
|
-
*
|
|
801
|
-
* @param {Object} sheet the generated key sheet
|
|
802
|
-
* @param {Number} count - the number of messages to generate
|
|
803
|
-
*
|
|
804
|
-
* @returns {Array} the list of generated messages
|
|
805
|
-
*/
|
|
806
|
-
generateMessages(sheet: any, count: number): any[];
|
|
807
|
-
}
|
|
808
|
-
import Enigma from "enigma/Enigma";
|
|
809
|
-
import Generator from "generator/Generator";
|
|
810
|
-
}
|
|
811
|
-
declare module "generator/index" {
|
|
812
|
-
export { default as Generator } from "./Generator.js";
|
|
813
|
-
export { default as CodeBook } from "./CodeBook.js";
|
|
814
|
-
export { default as Random } from "../utils/Random.js";
|
|
815
|
-
}
|
|
816
|
-
declare module "index" {
|
|
817
|
-
export * from "enigma/index";
|
|
818
|
-
export * from "generator/index";
|
|
819
|
-
}
|
|
820
|
-
declare module "enigma/tests/EnigmaData" {
|
|
821
|
-
export namespace enigmaData {
|
|
822
|
-
let sampleFieldMessages: ({
|
|
823
|
-
source: string;
|
|
824
|
-
model: string;
|
|
825
|
-
setup: {
|
|
826
|
-
reflector: string;
|
|
827
|
-
rotors: string[];
|
|
828
|
-
ringSettings: number[];
|
|
829
|
-
plugs: string;
|
|
830
|
-
};
|
|
831
|
-
message: {
|
|
832
|
-
key: string;
|
|
833
|
-
encoded: string;
|
|
834
|
-
decoded: string;
|
|
835
|
-
};
|
|
836
|
-
} | {
|
|
837
|
-
source: string;
|
|
838
|
-
model: string;
|
|
839
|
-
setup: {
|
|
840
|
-
reflector: string;
|
|
841
|
-
rotors: string[];
|
|
842
|
-
ringSettings: string;
|
|
843
|
-
plugs: string;
|
|
844
|
-
};
|
|
845
|
-
message: {
|
|
846
|
-
key: string;
|
|
847
|
-
encoded: string;
|
|
848
|
-
decoded: string;
|
|
849
|
-
};
|
|
850
|
-
})[];
|
|
851
|
-
let sampleVerifiedMessages: {
|
|
852
|
-
verified: string[];
|
|
853
|
-
model: string;
|
|
854
|
-
setup: {
|
|
855
|
-
rotors: string[];
|
|
856
|
-
plugs: string;
|
|
857
|
-
ringSettings: number[];
|
|
858
|
-
reflector: string;
|
|
859
|
-
};
|
|
860
|
-
message: {
|
|
861
|
-
key: string;
|
|
862
|
-
encoded: string;
|
|
863
|
-
decoded: string;
|
|
864
|
-
};
|
|
865
|
-
}[];
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
declare module "enigma/tests/EnigmaSpec" {
|
|
869
|
-
export {};
|
|
870
|
-
}
|
|
871
|
-
declare module "enigma/tests/PlugBoardData" {
|
|
872
|
-
export namespace plugBoardData {
|
|
873
|
-
let alphabet: string;
|
|
874
|
-
let plugSettings: string;
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
declare module "enigma/tests/PlugBoardSpec" {
|
|
878
|
-
export {};
|
|
879
|
-
}
|
|
880
|
-
declare module "enigma/tests/RotorData" {
|
|
881
|
-
export namespace rotorData {
|
|
882
|
-
namespace createData {
|
|
883
|
-
let alphabet: string;
|
|
884
|
-
let map: string;
|
|
885
|
-
let reverseMap: number[];
|
|
886
|
-
let turnovers: string;
|
|
887
|
-
let turnoversMap: number[];
|
|
888
|
-
}
|
|
889
|
-
namespace I {
|
|
890
|
-
let map_1: string;
|
|
891
|
-
export { map_1 as map };
|
|
892
|
-
let turnovers_1: string;
|
|
893
|
-
export { turnovers_1 as turnovers };
|
|
894
|
-
}
|
|
895
|
-
}
|
|
896
|
-
}
|
|
897
|
-
declare module "enigma/tests/RotorSpec" {
|
|
898
|
-
export {};
|
|
899
|
-
}
|
|
1
|
+
export * from "./generator/index.d.ts";
|
|
2
|
+
export * from "./enigma/index.d.ts";
|