@ondoher/enigma 1.0.2 → 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.
Files changed (49) hide show
  1. package/README.md +75 -48
  2. package/dist/index.d.ts +899 -0
  3. package/jsconfig.json +7 -1
  4. package/lib/enigma/Encoder.js +154 -12
  5. package/lib/enigma/Enigma.js +45 -59
  6. package/lib/enigma/EnigmaTypes.d.ts +115 -18
  7. package/lib/enigma/EntryDisc.js +2 -8
  8. package/lib/enigma/PlugBoard.js +4 -9
  9. package/lib/enigma/Reflector.js +5 -9
  10. package/lib/enigma/Rotor.js +43 -36
  11. package/lib/enigma/index.js +1 -1
  12. package/lib/enigma/tests/EnigmaSpec.js +21 -15
  13. package/lib/enigma/tests/RotorData.js +1 -1
  14. package/lib/enigma/tests/RotorSpec.js +3 -1
  15. package/lib/generator/CodeBook.js +3 -3
  16. package/lib/generator/Generator.js +6 -5
  17. package/lib/generator/GeneratorTypes.d.ts +2 -1
  18. package/lib/utils/Random.js +1 -1
  19. package/package.json +8 -2
  20. package/scripts/EnigmaData.js +236 -0
  21. package/scripts/hamlet.html +8880 -0
  22. package/scripts/make-validated-data.js +4 -0
  23. package/scripts/parseHamlet.js +32 -0
  24. package/scripts/test-messages.js +60 -0
  25. package/scripts/test.js +118 -0
  26. package/scripts/x +6446 -0
  27. package/tsconfig.json +19 -0
  28. package/types/enigma/Encoder.d.ts +128 -0
  29. package/types/enigma/Enigma.d.ts +88 -0
  30. package/types/enigma/EntryDisc.d.ts +17 -0
  31. package/types/enigma/Inventory.d.ts +91 -0
  32. package/types/enigma/PlugBoard.d.ts +26 -0
  33. package/types/enigma/Reflector.d.ts +14 -0
  34. package/types/enigma/Rotor.d.ts +59 -0
  35. package/types/enigma/consts.d.ts +1 -0
  36. package/types/enigma/index.d.ts +5 -0
  37. package/types/enigma/standardInventory.d.ts +71 -0
  38. package/types/enigma/tests/EnigmaData.d.ts +46 -0
  39. package/types/enigma/tests/EnigmaSpec.d.ts +1 -0
  40. package/types/enigma/tests/PlugBoardData.d.ts +4 -0
  41. package/types/enigma/tests/PlugBoardSpec.d.ts +1 -0
  42. package/types/enigma/tests/RotorData.d.ts +15 -0
  43. package/types/enigma/tests/RotorSpec.d.ts +1 -0
  44. package/types/generator/CodeBook.d.ts +82 -0
  45. package/types/generator/Generator.d.ts +67 -0
  46. package/types/generator/hamlet.d.ts +2 -0
  47. package/types/generator/index.d.ts +3 -0
  48. package/types/index.d.ts +899 -0
  49. package/types/utils/Random.d.ts +131 -0
package/README.md CHANGED
@@ -4,6 +4,7 @@
4
4
 
5
5
  # Table of Contents
6
6
  [Getting Started](#getting-started)
7
+
7
8
  [Simulation](#simulation)
8
9
  - [Events](#events)
9
10
  - [Plugboard](#plugboard)
@@ -37,7 +38,7 @@ You can then import this into your code like this:
37
38
  ```JavaScript
38
39
  import {Enigma} from '@ondoher/enigma';
39
40
 
40
- var enigma = new Enigma({reflector: 'B'});
41
+ var enigma = new Enigma("I", {reflector: 'B'});
41
42
  ```
42
43
 
43
44
  In addition to this api, there is also [documentation](https://github.com/Ondoher/enigma/blob/main/docs/enigma.md)
@@ -65,17 +66,83 @@ will be passed to every constructed component.
65
66
 
66
67
  The signature of this callback should look like this:
67
68
 
68
- `function (event, name, message, info)`
69
+ ---
70
+ `function (event, name, data)`
71
+
72
+ #### **Parameters**
73
+ - **event** - which event is being fired.
74
+ - **name** - the name of the component that has fired this event
75
+ - **data** - an object that contains information relevant to the event
76
+
77
+ ### **Event Types**
78
+ There are five different events, they are.
79
+ - **input** - fired when any component receives a signal
80
+ - **output** - fired when any component sends a signal
81
+ - **translate** - fired when a component outputs a signal, contains information
82
+ about both the input and the output
83
+ - **step** - fired when a rotor steps
84
+ - **double-step** - fired when a rotor performs the double step.
85
+
86
+ ### Common
87
+
88
+ Every event contains these parameters,
89
+
90
+ - **name** - contains the name of the component sending the event
91
+ - **type** - the type of component sending the event. This is one of *Entry Wheel*,
92
+ *Plugboard*, *Reflector*, *Rotor* and *Enigma*
93
+ - **description** - a human readable string that details the event
94
+ - **direction** - this is not sent for all events, but is for *input*, *output*,
95
+ and *translate*, it is one of:
96
+
97
+ - **right** - this is the direction the translation starts until it hits
98
+ the reflector
99
+ - **left** - this is the direction translation happens after going through
100
+ the reflector.
101
+ - **turn-around** - sent by the reflector
102
+ - **end-to-end** - sent by the Enigma
103
+
104
+
105
+ ### input
106
+ This event is fired when any component receives a signal. In addition to the
107
+ common fields, the data object contains these fields:
69
108
 
70
- ### **Parameters**
71
- - **event** a string that identifies the specific action being taken.
72
- - **name** the name of the class instance that has fired this event
73
- - **message** a string that describes the event taking place
74
- - **info** an object that contains information relevant to the event
109
+ - **input** - this is the input value, it can be either a string or a number
110
+
111
+ ### output
112
+
113
+ This event is fired sent when any component sends a signal. In addition to the
114
+ common fields, the data object contains these fields:
115
+
116
+ - **output** - this is the output value, it can be either a string or a number
117
+
118
+ ### translate
119
+
120
+ This event is fired when a component outputs a signal, contains information
121
+ about both the input and the output. In addition to the common fields, the data
122
+ object contains these fields:
123
+
124
+ - **input** - this is the input value, it can be either a string or a number
125
+ - **output** - this is the output value, it can be either a string or a number
126
+
127
+ ### step
128
+
129
+ This event is fired when a rotor steps. In addition to the common fields, the
130
+ data object contains these fields:
131
+
132
+ - **start** - the staring position of the rotor
133
+ - **stop** - the ending position of the rotor
134
+ - **turnover** - true if the the stepping reached the turnover point
75
135
 
76
136
  The specific events and data are defined in the class documentation that
77
137
  follows.
78
138
 
139
+ ### double-step
140
+
141
+ This event is fired when a rotor performs the double step. In addition to the
142
+ common fields, the data object contains these fields:
143
+
144
+ - **offset** - the new position of the rotor
145
+
79
146
  ## PlugBoard
80
147
  Create an instance of this class to simulate the plug board component of an
81
148
  Enigma.
@@ -122,16 +189,6 @@ Call this method to encode a value in the given direction, right vs left.
122
189
  #### **Returns**
123
190
  the output connector
124
191
 
125
- #### **Events**
126
-
127
- `encode-right, encode-left`
128
-
129
- These events will be fired during encoding. The info parameter will have these
130
- fields.
131
-
132
- - **input** the number of the connector that received input
133
- - **output** the number of the connector for the encoded value
134
-
135
192
  ## Rotor
136
193
 
137
194
  Create an instance of this class to construct a Rotor object. The Rotor class
@@ -276,16 +333,6 @@ between a left and right signal path.
276
333
  #### **Returns**
277
334
  the output connector
278
335
 
279
- ### **Events**
280
-
281
- `encode`
282
-
283
- This event will be fired during encoding. The info parameter will have these
284
- fields.
285
-
286
- - **input** the number of the connector that received input
287
- - **output** the number of the connector for the encoded value
288
-
289
336
  ## Enigma
290
337
 
291
338
  Create an instance of this class to construct a full Enigma.
@@ -378,26 +425,6 @@ Call this method to encode a whole string.
378
425
  the encoded string. Passing the result of this method back through the encode
379
426
  method should produce the original text.
380
427
 
381
- ### **Events**
382
-
383
- In addition to firing all the events from its components, the Enigma will also
384
- fire these events.
385
-
386
- `input`
387
-
388
- This is fired at the beginning of encoding each letter. It is fired after
389
- verifying the letter, but before stepping. The info parameter contains these
390
- fields.
391
-
392
- - **letter** the letter to be encoded
393
-
394
- `output`
395
-
396
- This is fired after encoding each letter. The info parameter contains these
397
- fields.
398
-
399
- - **letter** the encoded letter.
400
-
401
428
  ## **Properties**
402
429
 
403
430
  `configuration`
@@ -419,7 +446,7 @@ An array of the installed rotors
419
446
  ```javascript
420
447
  import {Enigma} from '@ondoher/enigma';
421
448
 
422
- var enigma = new Enigma({reflector: 'B'});
449
+ var enigma = new Enigma("I", {reflector: 'B'});
423
450
 
424
451
  enigma.configure({
425
452
  rotors: ['III', 'VI', 'VIII'],