@ondoher/enigma 0.1.7 → 1.0.1

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 CHANGED
@@ -2,6 +2,21 @@
2
2
  <img src="./enigma-toolkit-logo.png" height="100"/>
3
3
  </div>
4
4
 
5
+ # Table of Contents
6
+ [Getting Started](#getting-started)
7
+ [Simulation](#simulation)
8
+ - [Events](#events)
9
+ - [Plugboard](#plugboard)
10
+ - [Rotor](#rotor)
11
+ - [Reflector](#reflector)
12
+ - [Enigma](#enigma)
13
+ - [Example](#example)
14
+
15
+ [Generation](#generation)
16
+ - [Random](#random)
17
+ - [Generator](#generator)
18
+ - [CodeBook](#codebook)
19
+
5
20
  # Getting Started
6
21
 
7
22
  The Enigma toolkit is released as a nodejs ESM module. ESM is a relatively new
@@ -67,6 +82,7 @@ Enigma.
67
82
 
68
83
  ### **Methods**
69
84
 
85
+ ---
70
86
  `constructor(name, settings)`
71
87
 
72
88
  This is the constructor for the plugboard class. It takes these parameters:
@@ -80,6 +96,7 @@ plug board in the Enigma, so the name here doesn't really matter
80
96
  - _map_ (optional) set this to a string that will set the mapping between
81
97
  the position in the string to the output connector. Defaults to A-Z
82
98
 
99
+ ---
83
100
  `configure(settings)`
84
101
 
85
102
  Call this method to configure the plug board. This must be called even if there
@@ -92,6 +109,7 @@ are no plug connections.
92
109
  connects one input letter to another. If it is an array then then each item
93
110
  is a pair of letters to specify how the plugs are connected
94
111
 
112
+ ---
95
113
  `encode(direction, input)`
96
114
 
97
115
  Call this method to encode a value in the given direction, right vs left.
@@ -123,6 +141,7 @@ for an explanation.
123
141
 
124
142
  ### **Methods**
125
143
 
144
+ ---
126
145
  `constructor(name, settings)`
127
146
 
128
147
  #### **Parameters**
@@ -145,6 +164,7 @@ for an explanation.
145
164
  turnover locations, M and Z. Pass an empty string when the rotor does not
146
165
  rotate during stepping
147
166
 
167
+ ---
148
168
  `setStartPosition(connector)`
149
169
 
150
170
  Call this method to set the starting rotation for encoding.
@@ -153,6 +173,7 @@ Call this method to set the starting rotation for encoding.
153
173
  - **connector** This is a letter value that corresponds to what would appear in
154
174
  the rotation window. This value will be adjusted for the ring setting.
155
175
 
176
+ ---
156
177
  `encode(direction, input)`
157
178
 
158
179
  Call this method to map an input connector to an output connector when the
@@ -168,6 +189,7 @@ zero point we need to adjust the connector number for the current rotation.
168
189
  #### **Returns**
169
190
  the output connector in physical space
170
191
 
192
+ ---
171
193
  `step()`
172
194
 
173
195
  Call this method to step the rotor
@@ -175,6 +197,7 @@ Call this method to step the rotor
175
197
  #### **Returns**
176
198
  true if the next rotor should be stepped
177
199
 
200
+ ---
178
201
  `willTurnover()`
179
202
  Call this method to see if the next step on this rotor will lead to turn over.
180
203
  The Enigma class will call this on the middle rotor to handle double stepping.
@@ -182,7 +205,8 @@ The Enigma class will call this on the middle rotor to handle double stepping.
182
205
  #### **Returns**
183
206
  true if the next step will cause turnover
184
207
 
185
- `isfixed()`
208
+ ---
209
+ `isFixed()`
186
210
 
187
211
  Call this method to find whether this is a fixed rotor.
188
212
 
@@ -221,6 +245,7 @@ this, reflectors only encode in a single direction.
221
245
 
222
246
  ### **Methods**
223
247
 
248
+ ---
224
249
  `constructor(name, settings)`
225
250
 
226
251
  #### **Parameters**
@@ -236,6 +261,7 @@ this, reflectors only encode in a single direction.
236
261
  of this string at that index is the output connector. For example,
237
262
  'YRUHQSLDPXNGOKMIEBFZCWVJAT' which is the map for standard reflector B.
238
263
 
264
+ ---
239
265
  `encode(direction, input)`
240
266
 
241
267
  Call this method to encode a value when reversing the encoding direction of the
@@ -266,12 +292,13 @@ Create an instance of this class to construct a full Enigma.
266
292
 
267
293
  ### **Methods**
268
294
 
295
+ ---
269
296
  `constructor(settings)`
270
297
 
271
298
  The constructor for the Enigma.
272
299
 
273
300
  #### **Parameters**
274
- - **settings** The settings here are for the unconfigurable options of the
301
+ - **settings** The settings here are for the nonconfigurable options of the
275
302
  device.
276
303
  - _alphabet_ (optional) set this to a string of letters that are an
277
304
  alternative to the standard A-Z. Defaults to A-Z
@@ -281,6 +308,7 @@ The constructor for the Enigma.
281
308
  standard reflectors from the inventory which are A, B, and C. For the M4,
282
309
  Thin-B and Thin-C have been defined.
283
310
 
311
+ ---
284
312
  `configure(settings)`
285
313
 
286
314
  Call this method to configure the enigma instance for daily setup.
@@ -304,20 +332,23 @@ Call this method to configure the enigma instance for daily setup.
304
332
  array, is the ring setting for a rotor. Like the rotors, these are given
305
333
  from left to right.
306
334
 
335
+ ---
307
336
  `step()`
308
337
 
309
338
  Call this method to step the Enigma. This will rotate the first rotor to the
310
339
  right and step and double step when necessary.
311
340
 
341
+ ---
312
342
  `setStart(start)`
313
343
 
314
344
  #### **Parameters**
315
- - **start** this is either a string of an array of numbers. The length of the
345
+ - **start** this is either a string or an array of numbers. The length of the
316
346
  string or the array should match the number of rotors and are given left to
317
347
  right. If start is a string then the letters of the string specify the start
318
348
  value seen in the window for the corresponding rotor. If it is an array then
319
349
  each number will be the one-based rotation value.
320
350
 
351
+ ---
321
352
  `keyPress(letter)`
322
353
 
323
354
  Call this method to encode a single letter. This will step the Enigma before
@@ -332,6 +363,7 @@ encoding the letter.
332
363
  #### **Returns**
333
364
  undefined or the encoded character.
334
365
 
366
+ ---
335
367
  `encode(start, text)`
336
368
 
337
369
  Call this method to encode a whole string.
@@ -366,7 +398,23 @@ fields.
366
398
 
367
399
  - **letter** the encoded letter.
368
400
 
369
- ### **Example**
401
+ ## **Properties**
402
+
403
+ `configuration`
404
+ Use this property to get all the information necessary to reconstruct the
405
+ details on this Enigma. It is an object with these fields:
406
+
407
+ - **rotors** - this list of rotor names
408
+ - **ringSettings** - an array of ring settings for each rotor
409
+ - **plugs** - a space separated string of plug pairs
410
+ - **reflector** - the installed reflector
411
+
412
+ ---
413
+ `rotors`
414
+ An array of the installed rotors
415
+
416
+
417
+ ## **Example**
370
418
 
371
419
  ```javascript
372
420
  import {Enigma} from '@ondoher/enigma';
@@ -405,6 +453,7 @@ following components are already defined:
405
453
 
406
454
  ### **Methods**
407
455
 
456
+ ---
408
457
  `addRotor(name, map, turnovers)`
409
458
 
410
459
  Call this method to add a new rotor definition.
@@ -425,6 +474,7 @@ Call this method to add a new rotor definition.
425
474
  two turnover locations, 'M' and 'Z'. Pass an empty string if this is a fixed
426
475
  rotor
427
476
 
477
+ ---
428
478
  `addReflector(name, map)`
429
479
 
430
480
  Call this method to add a new reflector definition.
@@ -434,6 +484,7 @@ Call this method to add a new reflector definition.
434
484
  constructing an Enigma class.
435
485
  - **map** this uses the same format used in the `addRotor` method
436
486
 
487
+ ---
437
488
  `addEntryDisc(name, map)`
438
489
 
439
490
  Call this method to add a new entry disc. There was only one used in the
@@ -445,6 +496,7 @@ differently.
445
496
  constructing an Enigma class.
446
497
  - **map** this uses the same format used in the `addRotor` method
447
498
 
499
+ ---
448
500
  `getRotor(name)`
449
501
 
450
502
  Call this method to get the setup for a defined rotor.
@@ -457,6 +509,7 @@ an object with these fields
457
509
  - **map** the connection map for the rotor
458
510
  - **turnovers** the locations where turnovers happen
459
511
 
512
+ ---
460
513
  `getReflector(name)`
461
514
 
462
515
  Call this method to get the setup for a defined reflector.
@@ -468,6 +521,7 @@ Call this method to get the setup for a defined reflector.
468
521
  an object with these fields
469
522
  - **map** the connection map for the reflector
470
523
 
524
+ ---
471
525
  `getEntryDisc(name)`
472
526
 
473
527
  Call this method to get the setup for a defined entry disc.
@@ -479,93 +533,360 @@ Call this method to get the setup for a defined entry disc.
479
533
  an object with these fields
480
534
  - **map** the connection map for the entry disc
481
535
 
482
- # Message Generator
536
+ # Generation
537
+ The toolkit has the ability to generate random data that comes in two forms. The
538
+ first is the configuration of an Enigma and the generation of encrypted messages.
539
+ The second is the generation and use of message code books, specifically the
540
+ creation of key sheets and generation of messages using those key sheets. This
541
+ is implemented across three classes.
542
+
543
+ - **Random** - Umplements a seedable pseudo-random number generator. The use of
544
+ seeds allows running experiments on a predictable set of pseudo-random data
545
+ - **Generator** - Use this to create random configurations of an Enigma and
546
+ generate messages for that configuration.
547
+ - **CodeBook** - Use this to generate random key sheets and generate messages
548
+ using that key sheet
549
+
550
+ ## Random
551
+
552
+ A single instance of this class is the default export of the Random module. Use
553
+ this to generate pseudorandom numbers and perform randomization operations on
554
+ lists of items. This class uses a seedable pseudorandom number generator, this
555
+ enables the predictable generation of set of operations to reproduce the same
556
+ results.
557
+
558
+ ### **Methods**
559
+
560
+ ---
561
+ `randomize(seed)`
562
+
563
+ Call this method to set the random seed for the randomizer. Setting the seed
564
+ to a known value will cause to randomizer to output the same sequence of random
565
+ values. On creation the seed is set to `Date.now()`
566
+
567
+ #### **Parameters**
568
+ - **seed** - the new seed number
569
+
570
+ ---
571
+ `random(limit)`
572
+
573
+ Call this method to generate a new random number. If a limit is provided the
574
+ output will be a random number between 0 and limit-1. If not, the result will be
575
+ a decimal number between 0 and 1
576
+
577
+ #### **Parameters**
578
+ - **limit** (optional) - if provided the output will be an integer value less
579
+ than this
580
+
581
+ #### **Returns**
582
+ The pseudo-random number
583
+
584
+ ---
585
+ `randomCurve(dice, faces, zeroBased)`
586
+
587
+ Call this to generate a random number that is distributed along a bell curve.
588
+ This is done by generating a set of random numbers each within a limit, and
589
+ adding them together.
590
+
591
+ #### **Parameters**
592
+ - **dice** - the number of random numbers that should be chosen
593
+ - **faces** - the range of integer values
594
+ - **zeroBased** - if true the random numbers will start at 0, defaults to false
595
+
596
+ #### **Result**
597
+ The integer result
598
+
599
+ ---
600
+ `pickOne(list)`
601
+
602
+ Call this method to pick a random element from the provided array. The item will
603
+ be removed from this array. Use this method if you want to prevent the same item
604
+ from being used more than once.
605
+
606
+ #### **Parameters**
607
+ - **list** - an array if items to choose from.
608
+
609
+ #### **Returns**
610
+ The array element
611
+
612
+ ---
613
+ `pickPair(list)`
614
+
615
+ Call this method to pick two items from the provided array. The items will be
616
+ removed from the array. If the array is less than two items then it will return
617
+ either an empty array or an array with one element.
618
+
619
+ #### **Parameters**
620
+ - **list** - an array if items to choose from.
621
+
622
+ #### **Returns**
623
+ An array with the picked elements
624
+
625
+ ---
626
+ `pickPairs(count, list)`
627
+
628
+ Call this method to pick a list of item pairs from a list of items. The items
629
+ are removed from the list as chosen.
630
+
631
+ #### **Parameters**
632
+ - **count** - how many item pairs to pick
633
+ - **list** - an array if items to choose from.
634
+
635
+ #### **Returns**
636
+ An array of item pairs
637
+
638
+ ---
639
+ `pick(count, list)`
640
+
641
+ Call this method to pick a specified number of items from the list. The items
642
+ will be removed. It will return at most `list.length` elements.
483
643
 
484
- The message generator API consists of a single class `Generator` which is used
485
- to generate random test data.
644
+ #### **Parameters**
645
+ - **count** - how many items to pick
646
+ - **list** - an array if items to choose from.
647
+
648
+ #### **Returns**
649
+ An array with the chosen elements
650
+
651
+ ---
652
+ `chooseOne(list)`
653
+
654
+ Call this method to pick a random element from the provided array. The item will
655
+ remain in the list.
656
+
657
+ #### **Parameters**
658
+ - **list** - an array of items to choose from.
659
+
660
+ #### **Returns**
661
+ The array element
662
+
663
+ ---
664
+ `choosePair(list)`
665
+
666
+ Call this method to choose two items from the list, the elements will not be
667
+ removed. The returned items are guaranteed be different. If the array is less
668
+ than two elements it will be returned as the result
669
+
670
+ #### **Parameters**
671
+ - **list** - an array if items to choose from.
672
+
673
+ #### **Returns**
674
+ An array with the chosen elements
675
+
676
+ ---
677
+ `chooseRange(count, list)`
678
+
679
+ Call this method to pick a contiguous list of items from the given list. The
680
+ items will remain in the list.
681
+
682
+ #### **Parameters**
683
+ - **count** - how many items in the range
684
+ - **list** - an array if items to choose from.
685
+
686
+ #### **Returns**
687
+ An array with the chosen elements
688
+
689
+ ---
690
+ `choose(count, list)`
691
+
692
+ Call this method to choose a specified number if items from the list. The items
693
+ will not be removed. It may return the same item multiple times.
694
+
695
+ #### **Parameters**
696
+ - **count** - how many items to choose
697
+ - **list** - an array if items to choose from.
698
+
699
+ #### **Returns**
700
+ An array with the chosen elements
701
+
702
+ ---
486
703
 
487
704
  ## Generator
488
705
 
706
+ Use the generator class to generate random enigma machine configurations and use these to generate random messages.
707
+
489
708
  ### **Methods**
490
709
 
491
- `generateEncodedText(settings)`
710
+ `cleanMessage(text)`
492
711
 
493
- Call this method to generate some random text encoded with a random Enigma
494
- configuration. The random text will be a few sentences from Hamlet.
712
+ Call this method to prepare the string for encoding. The string will be converted to uppercase and remove any characters not within A-Z
495
713
 
496
714
  #### **Parameters**
497
- - **settings** (optional), alternative configuration settings for the Enigma
498
- - _rotors_ (optional) alternate list of rotors to choose from. Defaults to
499
- all defined rotors
500
- - _fixed_ (optional) an array of fixed rotors to choose from. Defaults to
501
- an empty list
502
- - _reflectors_ (optional) an array of reflectors to choose from. Defaults to
503
- A, B and C
715
+ - **text** - the text to clean
504
716
 
505
717
  #### **Returns**
506
- the generated text and meta data. This is an object with these fields
718
+ The cleaned up text
507
719
 
508
- - **setup** how the Enigma was configured
509
- - _rotors_ an array of three rotor names, four if a fixed list was given
510
- in the settings
511
- - _ringSettings_ an array of offsets for the ring settings
512
- - _plugs_ 10 pairs of letters that will be used as connections on the plug
513
- board
514
- - _reflector_ which reflector was configured
720
+ `groupText(text, size)`
515
721
 
516
- - **start** three letter or four string with the starting rotor offsets used to
517
- encode the text.
518
- - **message** the encoded text
519
- - **clear** the unencoded text. This is provided to validate the simulation
520
- result
722
+ Call this method to break the given text into groups of a given size,
723
+ separated by spaces.
521
724
 
522
- #### **Example**
725
+ #### **Parameters**
726
+ - **text** - the text to group
727
+ - **size** (optional) - the size of the groups, defaults to 5
523
728
 
524
- ```JavaScript
525
- // Generate messages for the Enigma Model I
526
- function generateI(count, list) {
527
- for (let idx = 0; idx < count; idx++) {
528
- let message = generator.generateEncodedText({
529
- rotors: ['I', 'II', 'III', 'IV', 'V'],
530
- reflectors: ['A', 'B', 'C'],
531
- })
532
- list.push({model: 'I', ...message});
729
+ #### **Returns**
730
+ The grouped text as a string
731
+
732
+ ---
733
+ `generateSentences(count)`
734
+
735
+ Call this method to generate an array of random sentences. These sentences will be a contiguous list of lines from Hamlet.
736
+
737
+ #### **Parameters**
738
+ - **count** - the number of sentences to generate
739
+
740
+ #### **Returns**
741
+ An array of sentences
742
+
743
+ ---
744
+ `getModelOptions(model)`
745
+
746
+ Call this method to get the range of setup and configuration options for
747
+ a specific Enigma model. The supported models are *I, M3 and M4*
748
+
749
+ #### Parameters
750
+ - **model** - the model of Enigma to use
751
+
752
+ #### Returns
753
+
754
+ An object with these fields
755
+
756
+ - **reflectors** - The names of the possible reflectors installed for this model.
757
+ - **rotors** - The names of the rotors available for this model
758
+ - **fixed** - the possible fixed rotors for this model
759
+
760
+ ---
761
+ `generateEnigmaConfiguration(setup)`
762
+
763
+ Call this method to get a random configuration for an enigma.
764
+
765
+ #### **Paramters**
766
+ - **setup** - the options for configuration with these fields
767
+ - **rotors** (optional) - the list of rotors to choose from. Defaults to
768
+ the list of unfixed rotors in the inventory
769
+ - **fixed** (optional) - if true, it defaults to the list of installed fixed
770
+ rotors, if an array, uses this array as the list of fixed rotors to choose
771
+ from. The default is an empty array.
772
+
773
+ #### **Returns**
774
+ An object with these fields>
775
+ - **rotors** - the rotors to install
776
+ - **plugs** - the plug board configuration as a string if space separated pairs
777
+ - **ringSettings** - an array of numbers for the ring setting for each rotor
778
+
779
+ ---
780
+ `createRandomEnigma(model, reflectors)`
781
+
782
+ Call this method to create a new Enigma object, with a reflector chosen from the
783
+ given list.
784
+
785
+ #### **Parameters**
786
+ - **model** (optional) - the model of the Enigma, defaults to the string "Enigma"
787
+ - **reflectors** (optional) - the possible reflectors, defaults to [A, B, C]
788
+
789
+ #### **Returns**
790
+ - a newly created `Enigma` instance
791
+
792
+ ---
793
+ `generateMessage(enigma)`
794
+
795
+ Call this method to create and encrypt a random message using the given Enigma.
796
+ The text of the message will be between 2 and 5 sentences from Hamlet.
797
+
798
+ #### **Parameters**
799
+
800
+ - **enigma** the `Enigma` instance to use
801
+
802
+ #### **Returns**
803
+ An object with these fields
804
+
805
+ - **start** - a string with the start positions for each rotor expressed as a
806
+ letter
807
+ - **decoded** - the clear text version of the message
808
+ - **encoded** - the encoded string using the given `Enigma` instance
809
+
810
+
811
+ ### **Example**
812
+
813
+ ```javascript
814
+ function generateForModel(model, count, list) {
815
+ let {reflectors, rotors, fixed} = generator.getModelOptions(model);
816
+ let enigma = generator.createRandomEnigma(model, reflectors)
817
+
818
+ for (let idx = 0; idx < count; idx++) {
819
+ let configuration = generator.generateEnigmaConfiguration({rotors, fixed});
820
+ enigma.configure(configuration);
821
+
822
+ let message = generator.generateMessage(enigma);
823
+
824
+ list.push({model, ...message});
825
+ }
533
826
  }
534
- }
827
+
828
+ let messages = [];
829
+
830
+ generateForModel('I', 5, messages);
831
+ generateForModel('M3', 5, messages);
832
+ generateForModel('M4', 5, messages);
535
833
  ```
536
834
 
537
- `generateEnigmaSetup(settings)`
835
+ ## CodeBook
836
+
837
+ Use this class to create [key sheets](https://www.ciphermachinesandcryptology.com/en/enigmaproc.htm)
838
+ and messages using those key sheets.
839
+
840
+ ### Key sheet
841
+ A key sheet specifies how to configure the enigma machine each day for a whole
842
+ month. It consisted of one line per day, sorted from the last day of the month
843
+ until the first. Each line had these columns:
538
844
 
539
- Call this method to generate a random Enigma setup. This includes only the
540
- configurable items, it does not include the details of the machine itself.
845
+ - **date (Datum)** - the numerical day of the month
846
+ - **rotor setup (Walzenlage)** - the rotors to use
847
+ - **ring settings (Ringstellung)** - the ring setting for each rotor
848
+ - **plugboard configuration (Steckerverbindungen)** - how the ten plugs where
849
+ connected to the plugboard
850
+ - **indicators (Kenngruppen)** - a set of four three digits codes that were an
851
+ index into the specific day
852
+
853
+ ---
854
+ ### **Methods**
855
+
856
+ `constructor(enigma)`
857
+
858
+ This is the constructor for the `CodeBook`. Each instance of this class works
859
+ with an instance of the `Enigma` class.
541
860
 
542
861
  #### **Parameters**
543
- - **settings** (optional), alternative configuration settings for the Enigma
544
- - _rotors_ (optional) alternate list of rotors to choose from. This will
545
- default to all defined rotors except those that are fixed.
546
- _fixed_ (optional) an array of fixed rotors to choose one from. Defaults to
547
- an empty list
862
+ - **enigma** - the `Enigma` instance to use.
548
863
 
549
- #### **Returns**
550
- the generated settings. This is an obejct with these fields
864
+ ---
865
+ `configure(config)`
551
866
 
552
- - **rotors** an array of three rotor names, four if fixed was given in the
553
- settings
554
- - **ringSettings** an array of offsets for the ring settings
555
- - **plugs** 10 pairs of letters that will be used as connections on the plug
556
- board
867
+ Call this method to configure the `Enigma` used by this instance.
868
+
869
+ #### **Parameters**
870
+
871
+ - **config** - the simplified configuration returned by `Generator.generateEnigmaConfiguration`.
872
+ it has these fields.
873
+ - **rotors** - the rotors to install
874
+ - **plugs** - the plug board configuration as a string if space separated pairs
875
+ - **ringSettings** - an array of numbers for the ring setting for each rotor
557
876
 
877
+
878
+ ---
558
879
  `generateKeySheet(days)`
559
880
 
560
881
  Call this method to generate a monthly key sheet. This is the same data that
561
- would have been used by officers to setup the Enigma every day. The keysheet
562
- is generated for an M3 (rotors I-VIII) using reflector B
882
+ would have been used by officers to setup the Enigma every day. The key sheet
883
+ is created based on the enigma instance
563
884
 
564
885
  #### **Parameters**
565
886
  - **days** The number of days to generate data for
566
887
 
567
888
  #### **Returns**
568
- the key sheet which is an array of objects, each one with these fields
889
+ An array of objects, each one with these fields
569
890
 
570
891
  - **day** the day of the month
571
892
  - **rotors** an array of three rotor names
@@ -575,10 +896,12 @@ the key sheet which is an array of objects, each one with these fields
575
896
  - **indicators** and array of four three-letter strings. These strings will be
576
897
  unique across the key sheet
577
898
 
578
- `generateMessages(sheet, count)`
579
899
 
580
- Call this method to create an array of messages based off a key sheet. This has
581
- the same informaton that a message in the field would possess. The construction
900
+ ---
901
+ `generateMessage(sheet, dayIdx, text)`
902
+
903
+ Call this method to generate a message using the given key sheet. Each message has
904
+ the same information that a message in the field would possess. The construction
582
905
  of the message follow the the standards of the German military beginning in
583
906
  1940. They are as follows:
584
907
 
@@ -599,44 +922,82 @@ key identifiers from the key sheet that defines the Enigma configuration. The
599
922
  first two characters of this group were randomly chosen, and the last three were
600
923
  one of the key identifiers for that daily setup. This text was not encrypted.
601
924
 
925
+
602
926
  #### **Parameters**
603
- - **sheet** a key sheet as generated from `generateKeySheet`
604
- - **count** the number of messages to create
927
+ - **sheet** - the key sheet to use
928
+ - **dayIdx** (optional) - if specified the zero-based day to use, defaults to
929
+ a random day
930
+ - **text** (optional) - if provided will be used as the text of the message.
931
+ Defaults to between two and five contiguous lines from Hamlet
605
932
 
606
933
  #### **Returns**
607
- an array of messages. Each message is an array of sub messages. A message was
608
- broken down into text blocks that were no longer than 250 characters and sent
609
- in multiple parts. These sub messages were sent using a unique key and start
610
- position. These are the fields in a sub message.
611
-
612
- - **key** a randomly chosen key, this would be transmitted with the message
613
- - **enc** the encoded start position for the message. This was encoded using
934
+ The configuration of the Enigma and an array of sub messages, which could be
935
+ longer than one for large messages.
936
+
937
+ The returned object has these fields
938
+ - **options**- the configuration used to generate the message
939
+ - **rotors** - the installed rotors to install
940
+ - **plugs** - the plug board configuration as a string of space separated pairs
941
+ - **ringSettings** - an array of numbers for the ring setting for each rotor
942
+ - **reflector**- the installed reflector
943
+ - **parts** - an array of sub messages, each with these fields
944
+ - **key** - a randomly chosen key, this would be transmitted with the message
945
+ - **enc** - the encoded start position for the message. This was encoded using
614
946
  the randomly chosen key. This was sent with the message
615
- - **text** the message text encoded using the unencoded start position. The
616
- first five letters of this text string included the unencrypted key
617
- identifier.
618
- - **start** the unencoded start position. This was not sent with the message but
619
- is included here to verify an implementation of this method.
620
- - **clear** the unencrypted message. This can be used to verify an
621
- implementation of this method.
947
+ - **text** - the message text encoded using the unencoded start position. The
948
+ first five letters of this text string included the unencrypted key
949
+ identifier.
950
+ - **start** - the unencoded start position. This was not sent with the message but
951
+ is included here to verify an implementation of this method.
952
+ - **clear** - the unencrypted message. This can be used to verify an
953
+ implementation of this method.
954
+
955
+ ---
956
+ `generateMessages(sheet, count)`
957
+
958
+ Call this method to create an array of messages based off a key sheet. This
959
+ method calls `generateMessage` count times.
960
+
961
+ #### **Parameters**
962
+ - **sheet** - a key sheet as generated from `generateKeySheet`
963
+ - **count** - the number of messages to create
964
+
965
+ #### **Returns**
966
+ An array of messages as returned from `generateKeySheet`
622
967
 
623
968
  #### **Example Message**
624
969
 
625
970
  ```json
626
- [
627
- {
628
- "key": "YSR",
629
- "enc": "MHH",
630
- "start": "GJC",
631
- "text": "OAYXJ CTCBV BZRBS SORIL YVMMM LLIVS OBUYU VMQTJ GFSZU XYUDR GHKRX KRCDV QEZCH MDTAJ KZUXV TZPOA VSCFH ILWQC DJNAH PILTN MMLHK OULDS QIMCB NMTRZ OQFQY CVWVW QXEHU WCMKJ XGUSA YPBIE EXGKZ LZLUF NMJNB ISUWN DYOWW XUJNK VUYOV SJOSW MQNSP MUTAZ DQIXV RGJXM ",
632
- "clear": "WHATD EVILW ASTTH ATTHU SHATH COZEN DYOUA THOOD MANBL INDEY ESWIT HOUTF EELIN GFEEL INGWI THOUT SIGHT EARSW ITHOU THAND SOREY ESSME LLING SANSA LLORB UTASI CKLYP ARTOF ONETR UESEN SECOU LDNOT SOMOP EOSHA MEWHE REIST HYBLU SHREB ELLIO USHEL LIFTH"
971
+ {
972
+ "options": {
973
+ "reflector": "A",
974
+ "rotors": [
975
+ "IV",
976
+ "III",
977
+ "II"
978
+ ],
979
+ "ringOffsets": [
980
+ 25,
981
+ 11,
982
+ 18
983
+ ],
984
+ "plugs": "AV XQ YK TD HE OB ZW FP IU CM"
633
985
  },
634
- {
635
- "key": "MYR",
636
- "enc": "AJI",
637
- "start": "ETH",
638
- "text": "OAYXJ WPIFA NPUKR ZWSZG GXYZX ZYTMQ PHVNB CPHUA XEUVC VOGUZ LPQSP RFHTK ZNFHL OYGEU ZGOPG EFBTL ORNDH INNGD LDIAT DDPOP QZZKE XBUWI VCJOW LWDJO BLASV JTOMG LUDRC LIISC DJZES QZSSD GBYSG PUGHS EWADO KDSFP ZOLBL RPEYX YKQTF HOI",
639
- "clear": "OUCAN STMUT INEIN AMATR ONSBO NESTO FLAMI NGYOU THLET VIRTU EBEAS WAXAN DMELT INHER OWNFI REPRO CLAIM NOSHA MEWHE NTHEC OMPUL SIVEA RDOUR GIVES THECH ARGES INCEF ROSTI TSELF ASACT IVELY DOTHB URNAN DREAS ONPAN DERSW ILL"
640
- }
641
- ]
986
+ "parts": [
987
+ {
988
+ "key": "VAH",
989
+ "enc": "WFL",
990
+ "start": "ZKY",
991
+ "text": "PYVJF SVGQI FUNUE RVYRN BPTJL TGGPW CAWXU NBAZS BTNUV XVEPE QOQGP AKMJM ILBYA MKMXD NVJMO HBVJB HBRZX QSPQX DFIBG JXOHN KQXTI OJBUP JWBCF UOMGJ XUJPP XBJEM LVKMA LZSKO VSOEC NIJFV TRLAO JLVOO TMQDU TYSWL HIAPE YYAQD QKANA IHVSG JMJIC MZOSP POWJI IZJMF VKARE YINLU SYBZY XKWAC UIHVO MKCFH BEPUG LAXWP ",
992
+ "clear": "HEMADECONFESSIONOFYOUANDGAVEYOUSUCHAMASTERLYREPORTFORARTANDEXERCISEINYOURDEFENCEANDFORYOURRAPIERMOSTESPECIALLYTHATHECRIEDOUTTWOULDBEASIGHTINDEEDIFONECOULDMATCHYOUTHESCRIMERSOFTHEIRNATIONHESWOREHADHADNEITHERMOTIONGUARDNOREYEIFYOUOPPOSEDTHEMSIRTHI"
993
+ },
994
+ {
995
+ "key": "TBR",
996
+ "enc": "AZP",
997
+ "start": "CBC",
998
+ "text": "RRRNG VYBRV RPVBF KFHAJ TPUHW WGZJU BWXGH LGNKW RYZYP DGBYC SUTEX KJSUX UDWER YJHDB HDSZH PARUG EPDXE YXBDX TBCKD JKYDY VLZVV ACYVD MTLEC BSQEP ACKVV YKJAZ SHQQT GMBQB T",
999
+ "clear": "REPORTOFHISDIDHAMLETSOENVENOMWITHHISENVYTHATHECOULDNOTHINGDOBUTWISHANDBEGYOURSUDDENCOMINGOERTOPLAYWITHHIMNOWOUTOFTHISWHATOUTOFTHISMYLORD"
1000
+ }
1001
+ ]
1002
+ }
642
1003
  ```