@ondoher/enigma 1.0.3 → 1.0.5
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/README.md +72 -46
- package/dist/index.d.ts +899 -0
- package/jsconfig.json +2 -2
- package/lib/enigma/Encoder.js +52 -18
- package/lib/enigma/Enigma.js +10 -9
- package/lib/enigma/EnigmaTypes.d.ts +17 -12
- package/lib/enigma/PlugBoard.js +1 -1
- package/lib/enigma/Reflector.js +1 -1
- package/lib/enigma/Rotor.js +3 -2
- package/lib/enigma/index.js +1 -1
- package/lib/enigma/tests/EnigmaSpec.js +5 -5
- package/lib/generator/CodeBook.js +3 -3
- package/lib/generator/Generator.js +5 -4
- package/lib/generator/GeneratorTypes.d.ts +2 -1
- package/lib/utils/Random.js +1 -1
- package/package.json +8 -2
- package/scripts/EnigmaData.js +236 -0
- package/scripts/hamlet.html +8880 -0
- package/scripts/make-validated-data.js +4 -0
- package/scripts/parseHamlet.js +32 -0
- package/scripts/test-messages.js +60 -0
- package/scripts/test.js +118 -0
- package/scripts/x +6446 -0
- package/tsconfig.json +19 -0
- package/types/enigma/Encoder.d.ts +128 -0
- package/types/enigma/Enigma.d.ts +88 -0
- package/types/enigma/EntryDisc.d.ts +17 -0
- package/types/enigma/Inventory.d.ts +91 -0
- package/types/enigma/PlugBoard.d.ts +26 -0
- package/types/enigma/Reflector.d.ts +14 -0
- package/types/enigma/Rotor.d.ts +59 -0
- package/types/enigma/consts.d.ts +1 -0
- package/types/enigma/index.d.ts +5 -0
- package/types/enigma/standardInventory.d.ts +71 -0
- package/types/enigma/tests/EnigmaData.d.ts +46 -0
- package/types/enigma/tests/EnigmaSpec.d.ts +1 -0
- package/types/enigma/tests/PlugBoardData.d.ts +4 -0
- package/types/enigma/tests/PlugBoardSpec.d.ts +1 -0
- package/types/enigma/tests/RotorData.d.ts +15 -0
- package/types/enigma/tests/RotorSpec.d.ts +1 -0
- package/types/generator/CodeBook.d.ts +82 -0
- package/types/generator/Generator.d.ts +67 -0
- package/types/generator/hamlet.d.ts +2 -0
- package/types/generator/index.d.ts +3 -0
- package/types/index.d.ts +899 -0
- package/types/utils/Random.d.ts +131 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this class to generate Enigma key sheets and messages using it. The
|
|
3
|
+
* procedures used were derived from the information at
|
|
4
|
+
* [Enigma Message Procedures](https://www.ciphermachinesandcryptology.com/en/enigmaproc.htm)
|
|
5
|
+
*/
|
|
6
|
+
export default class CodeBook {
|
|
7
|
+
/**
|
|
8
|
+
* Constructor for the `CodeBook` class.
|
|
9
|
+
* @param {Enigma} enigma - all encryption will be done using this configured Enigma
|
|
10
|
+
*/
|
|
11
|
+
constructor(enigma: Enigma);
|
|
12
|
+
enigma: Enigma;
|
|
13
|
+
indicators: {};
|
|
14
|
+
generator: Generator;
|
|
15
|
+
/**
|
|
16
|
+
* Call this method to provide a new configuration to the enigma
|
|
17
|
+
*
|
|
18
|
+
* @param {SimplifiedConfiguration} config
|
|
19
|
+
*/
|
|
20
|
+
configure(config: SimplifiedConfiguration): void;
|
|
21
|
+
reset(): void;
|
|
22
|
+
/**
|
|
23
|
+
* Call this method to create a three letter string as an identifier for a
|
|
24
|
+
* a day in a key sheet
|
|
25
|
+
*
|
|
26
|
+
* @returns {String} the string
|
|
27
|
+
*/
|
|
28
|
+
makeIndicator(): string;
|
|
29
|
+
/**
|
|
30
|
+
* Call this method to create a single days configuration for a key sheet.
|
|
31
|
+
* This an Enigma configuration plus the other metadata.
|
|
32
|
+
*
|
|
33
|
+
* @param {number} day the day of the month
|
|
34
|
+
*
|
|
35
|
+
* @returns {KeySheetLine} One line of a key sheet
|
|
36
|
+
*/
|
|
37
|
+
generateDay(day: number): KeySheetLine;
|
|
38
|
+
/**
|
|
39
|
+
* Call this method to construct a key sheet for the given number of days
|
|
40
|
+
*
|
|
41
|
+
* @param {Number} days the number of days on the key sheet
|
|
42
|
+
* @returns {KeySheetLine[]} the array of day objects
|
|
43
|
+
*/
|
|
44
|
+
generateKeySheet(days: number): KeySheetLine[];
|
|
45
|
+
/**
|
|
46
|
+
* Call this method to process one sub-message from a longer message. This is
|
|
47
|
+
* part of code to generate a message as the Enigma would have been used.
|
|
48
|
+
*
|
|
49
|
+
* @param {string[]} indicators the three letter code that can be sent to
|
|
50
|
+
* reference the configuration of the Enigma. These will be used to cross
|
|
51
|
+
* reference the message to the machine configuration on the key sheet
|
|
52
|
+
* @param {String} text the cleaned up string to be encoded
|
|
53
|
+
*
|
|
54
|
+
* @returns {MessagePart} the encoded message segment
|
|
55
|
+
*/
|
|
56
|
+
encodeOnePart(indicators: string[], text: string): MessagePart;
|
|
57
|
+
/**
|
|
58
|
+
* Call this method to generate a full message based on the data in a key
|
|
59
|
+
* sheet. The message constructed reflects an actual message as the Enigma
|
|
60
|
+
* was really used. An individual message cannot be more than 250
|
|
61
|
+
* characters, so longer messages are broken into multiple parts, each one
|
|
62
|
+
* encoded with a unique key
|
|
63
|
+
*
|
|
64
|
+
* @param {KeySheetLine[]} sheet a key sheet generated using generateKeySheet
|
|
65
|
+
* @param {number} [dayIdx] - if provided, specifies the day of the month for the message
|
|
66
|
+
* @param {string} [text] - if provided, this is the text of the message to generate
|
|
67
|
+
* @returns {KeyBookMessage} a list of encoded sub messages
|
|
68
|
+
*/
|
|
69
|
+
generateMessage(sheet: KeySheetLine[], dayIdx?: number, text?: string): KeyBookMessage;
|
|
70
|
+
/**
|
|
71
|
+
* Call this method to generate a given number of messages based on a
|
|
72
|
+
* generated key sheet
|
|
73
|
+
*
|
|
74
|
+
* @param {Object} sheet the generated key sheet
|
|
75
|
+
* @param {Number} count - the number of messages to generate
|
|
76
|
+
*
|
|
77
|
+
* @returns {Array} the list of generated messages
|
|
78
|
+
*/
|
|
79
|
+
generateMessages(sheet: any, count: number): any[];
|
|
80
|
+
}
|
|
81
|
+
import Enigma from '../enigma/Enigma.js';
|
|
82
|
+
import Generator from './Generator.js';
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Use this class to generate random enigma configurations and messages. The
|
|
3
|
+
* methods in this class all the use the `Random` object, which can be seeded to
|
|
4
|
+
* produce a reproducible output
|
|
5
|
+
*/
|
|
6
|
+
export default class Generator {
|
|
7
|
+
/**
|
|
8
|
+
* Call this method to turn a string into valid characters for encryption,
|
|
9
|
+
* which is just the letters A-Z.
|
|
10
|
+
*
|
|
11
|
+
* @param {String} text the original text
|
|
12
|
+
* @returns {String} the text that has been normalized to what the Enigma
|
|
13
|
+
* can process
|
|
14
|
+
*/
|
|
15
|
+
cleanMessage(text: string): string;
|
|
16
|
+
/**
|
|
17
|
+
* Call this method to break a string into groups of five letters with a
|
|
18
|
+
* space between them.
|
|
19
|
+
*
|
|
20
|
+
* @param {string} text - the original text
|
|
21
|
+
* @param {number} [size] - the size of the text groups, defaults to 5
|
|
22
|
+
*
|
|
23
|
+
* @returns {string} the segmented string
|
|
24
|
+
*/
|
|
25
|
+
groupText(text: string, size?: number): string;
|
|
26
|
+
/**
|
|
27
|
+
* Call this method to generate the given number of sentences. The sentences
|
|
28
|
+
* are pulled from the text of Hamlet.
|
|
29
|
+
*
|
|
30
|
+
* @param {Number} count the number of sentences
|
|
31
|
+
* @returns {String} the sentences separated by a ' ';
|
|
32
|
+
*/
|
|
33
|
+
generateSentences(count: number): string;
|
|
34
|
+
/**
|
|
35
|
+
* Call this method to get the possible setup and configuration options for
|
|
36
|
+
* the given model
|
|
37
|
+
*
|
|
38
|
+
* @param {Model} model
|
|
39
|
+
*
|
|
40
|
+
* @returns {ModelOptions}
|
|
41
|
+
*/
|
|
42
|
+
getModelOptions(model: Model): ModelOptions;
|
|
43
|
+
/**
|
|
44
|
+
* Call this method to generate a random Enigma configuration
|
|
45
|
+
*
|
|
46
|
+
* @param {GeneratorSetup} [setup] options for settings
|
|
47
|
+
|
|
48
|
+
* @returns {SimplifiedConfiguration} the Enigma settings.
|
|
49
|
+
*/
|
|
50
|
+
generateEnigmaConfiguration(setup?: GeneratorSetup): SimplifiedConfiguration;
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
* @param {string[]} [reflectors] if given, specifies and alternate list of
|
|
54
|
+
* reflectors. Defaults to ['A', 'B', 'C'];
|
|
55
|
+
*/
|
|
56
|
+
createRandomEnigma(model?: string, reflectors?: string[]): Enigma;
|
|
57
|
+
/**
|
|
58
|
+
* Call this method to generate a random message text encoded with the given
|
|
59
|
+
* Enigma. The random text will be a few sentences from Hamlet.
|
|
60
|
+
*
|
|
61
|
+
* @param {Enigma} enigma
|
|
62
|
+
*
|
|
63
|
+
* @returns {GeneratedMessage} details of the generated text
|
|
64
|
+
*/
|
|
65
|
+
generateMessage(enigma: Enigma): GeneratedMessage;
|
|
66
|
+
}
|
|
67
|
+
import Enigma from '../enigma/Enigma.js';
|