@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
@@ -0,0 +1,131 @@
1
+ declare const _default: Random;
2
+ export default _default;
3
+ /**
4
+ * This class implements a pseudorandom number generator that can be given a
5
+ * seed to produce a consistent sequence of numbers. This algorithm is
6
+ * inappropriate for real cryptographic purposes, but allows the production of
7
+ * output that can be consistently reproduced.
8
+ *
9
+ * This algorithm was stolen from the product Delphi.
10
+ */
11
+ declare class Random {
12
+ randSeed: number;
13
+ /**
14
+ * Call this method to set the seed value for the randomizer. The initial value
15
+ * will be the current time in milliseconds.
16
+ *
17
+ * @param {Number} value for the seed,
18
+ */
19
+ randomize(value: number): void;
20
+ /**
21
+ * Call this method to get a random number. If passed a value, the return
22
+ * will be an integer between 0 and that number - 1. without it will be a
23
+ * decimal value between 0 and < 1.
24
+ *
25
+ * @param {Number} [limit] if passed the upper boundary of the integer - 1
26
+ *
27
+ * @returns {Number} the randomized value as either an integer or a decimal
28
+ * value depending on how it was called.
29
+ */
30
+ random(limit?: number): number;
31
+ /**
32
+ * Generate a random number using a bell curve. The curve is created using
33
+ * the analogy of dice. For example, a random number built with two six
34
+ * sided dice will have the peak of the curve at 7 with 2 and 12 being at
35
+ * the bottom.
36
+ *
37
+ * @param {number} dice - how many random numbers to pick
38
+ * @param {number} faces - the range, from 1 - faces, of the number
39
+ * @param {boolean} [zeroBased] - if true, the random range for each die will be from 0 - faces-1
40
+ *
41
+ * @return {number} the random number
42
+ */
43
+ randomCurve(dice: number, faces: number, zeroBased?: boolean): number;
44
+ /**
45
+ * call this method to pick a random number from an array and remove it
46
+ *
47
+ * @template T
48
+ * @param {T[]} list the array of items to choose from
49
+ *
50
+ * @returns {T} the chosen item
51
+ */
52
+ pickOne<T>(list: T[]): T;
53
+ /**
54
+ * Call this method to pick two items from a given list. The items are
55
+ * removed from the array. If the array is less than two items then it
56
+ * will return either an empty array or an array with one element.
57
+ *
58
+ * @template T
59
+ *
60
+ * @param {T[]} list the array of items to choose
61
+ * @returns {T[]} the two chosen items
62
+ */
63
+ pickPair<T>(list: T[]): T[];
64
+ /**
65
+ * Call this method to choose a given number of items from a list. The items
66
+ * are removed.
67
+ *
68
+ * @template T
69
+ *
70
+ * @param {Number} count the number of items to pick
71
+ * @param {T[]} list the list of items to choose from
72
+ *
73
+ * @returns {T[]} the chosen items
74
+ */
75
+ pick<T>(count: number, list: T[]): T[];
76
+ /**
77
+ * Call this method to randomly pick a set of item pairs. The items
78
+ * will be removed from the list.
79
+ *
80
+ * @template T
81
+ * @param {Number} count the number of pairs to pick
82
+ * @param {T[]} list the list of items to choose from
83
+ *,
84
+ * @returns {T[][]}} the item pairs chosen. Each pair is an array of
85
+ * two items from the list
86
+ */
87
+ pickPairs<T>(count: number, list: T[]): T[][];
88
+ /**
89
+ * Call this method to chose a random item from a list. The item is not
90
+ * removed.
91
+ *
92
+ * @template T
93
+ *
94
+ * @param {T[]} list the list of items to choose from
95
+ * @returns {T} the chosen item
96
+ */
97
+ chooseOne<T>(list: T[]): T;
98
+ /**
99
+ * Call this method to pick a pair of items from the given list. The items
100
+ * are guaranteed to be unique.
101
+ *
102
+ * @template T
103
+ *
104
+ * @param {T[]} list - the list of items
105
+ * @returns {T[]}
106
+ */
107
+ choosePair<T>(list: T[]): T[];
108
+ /**
109
+ * Call this method to return a random list of contiguous items from the
110
+ * given list. The items are not removed.
111
+ *
112
+ * @template T
113
+ * @param {number} count
114
+ * @param {T[]} list
115
+ *
116
+ * return {T[]}
117
+ */
118
+ chooseRange<T>(count: number, list: T[]): string;
119
+ /**
120
+ * Call this method to randomly pick a subset of items from a list. The
121
+ * items are not removed.
122
+ *
123
+ * @template T
124
+ *
125
+ * @param {Number} count the number of items to choose
126
+ * @param {T[]} list the list of items to choose from
127
+ *
128
+ * @returns {T[]} the list of items chosen
129
+ */
130
+ choose<T>(count: number, list: T[]): T[];
131
+ }