@ondoher/enigma 1.0.3 → 1.0.6

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.
Files changed (46) hide show
  1. package/README.md +72 -46
  2. package/dist/index.d.ts +899 -0
  3. package/jsconfig.json +2 -2
  4. package/lib/enigma/Encoder.js +52 -18
  5. package/lib/enigma/Enigma.js +10 -9
  6. package/lib/enigma/EnigmaTypes.d.ts +17 -12
  7. package/lib/enigma/PlugBoard.js +1 -1
  8. package/lib/enigma/Reflector.js +1 -1
  9. package/lib/enigma/Rotor.js +3 -2
  10. package/lib/enigma/index.js +1 -1
  11. package/lib/enigma/tests/EnigmaSpec.js +5 -5
  12. package/lib/generator/CodeBook.js +3 -3
  13. package/lib/generator/Generator.js +5 -4
  14. package/lib/generator/GeneratorTypes.d.ts +2 -1
  15. package/lib/utils/Random.js +1 -1
  16. package/package.json +7 -2
  17. package/scripts/EnigmaData.js +236 -0
  18. package/scripts/hamlet.html +8880 -0
  19. package/scripts/make-validated-data.js +4 -0
  20. package/scripts/parseHamlet.js +32 -0
  21. package/scripts/test-messages.js +60 -0
  22. package/scripts/test.js +118 -0
  23. package/scripts/x +6446 -0
  24. package/tsconfig.json +19 -0
  25. package/types/enigma/Encoder.d.ts +128 -0
  26. package/types/enigma/Enigma.d.ts +88 -0
  27. package/types/enigma/EntryDisc.d.ts +17 -0
  28. package/types/enigma/Inventory.d.ts +91 -0
  29. package/types/enigma/PlugBoard.d.ts +26 -0
  30. package/types/enigma/Reflector.d.ts +14 -0
  31. package/types/enigma/Rotor.d.ts +59 -0
  32. package/types/enigma/consts.d.ts +1 -0
  33. package/types/enigma/index.d.ts +5 -0
  34. package/types/enigma/standardInventory.d.ts +71 -0
  35. package/types/enigma/tests/EnigmaData.d.ts +46 -0
  36. package/types/enigma/tests/EnigmaSpec.d.ts +1 -0
  37. package/types/enigma/tests/PlugBoardData.d.ts +4 -0
  38. package/types/enigma/tests/PlugBoardSpec.d.ts +1 -0
  39. package/types/enigma/tests/RotorData.d.ts +15 -0
  40. package/types/enigma/tests/RotorSpec.d.ts +1 -0
  41. package/types/generator/CodeBook.d.ts +82 -0
  42. package/types/generator/Generator.d.ts +67 -0
  43. package/types/generator/hamlet.d.ts +2 -0
  44. package/types/generator/index.d.ts +3 -0
  45. package/types/index.d.ts +899 -0
  46. 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';
@@ -0,0 +1,2 @@
1
+ export default sentences;
2
+ declare const sentences: string[];
@@ -0,0 +1,3 @@
1
+ export { default as Generator } from "./Generator.js";
2
+ export { default as CodeBook } from "./CodeBook.js";
3
+ export { default as Random } from "../utils/Random.js";