bgneal@64
|
1 Key lists
|
bgneal@64
|
2 ---------
|
bgneal@64
|
3
|
bgneal@64
|
4 Key lists are represented as a named tuple called ``KeyList``.
|
bgneal@64
|
5
|
bgneal@64
|
6 .. class:: m209.keylist.KeyList(indicator, lugs, pin_list, letter_check)
|
bgneal@64
|
7
|
bgneal@64
|
8 As a named tuple, ``KeyList`` has the following attributes:
|
bgneal@64
|
9
|
bgneal@64
|
10 * ``indicator`` - the string name for the ``KeyList``; must be 2 letters in
|
bgneal@64
|
11 the range ``AA`` - ``ZZ``
|
bgneal@64
|
12 * ``lugs`` - a string representing the drum lug settings; see below
|
bgneal@64
|
13 * ``pin_list`` - a list of six strings which represent key wheel pin
|
bgneal@64
|
14 settings; see below
|
bgneal@64
|
15 * ``letter_check`` - a string representing the letter check used to verify
|
bgneal@64
|
16 operator settings; if unknown this can be ``None`` or an empty string
|
bgneal@64
|
17
|
bgneal@64
|
18 Lug settings format
|
bgneal@64
|
19 ~~~~~~~~~~~~~~~~~~~
|
bgneal@64
|
20
|
bgneal@64
|
21 Drum lug settings are often conveniently represented as strings consisting of
|
bgneal@64
|
22 at most 27 whitespace-separated pairs of integers separated by dashes. For
|
bgneal@64
|
23 example::
|
bgneal@64
|
24
|
bgneal@64
|
25 lugs = '1-0 2-0 2-0 0-3 0-5 0-5 0-5 0-6 2-4 3-6'
|
bgneal@64
|
26
|
bgneal@64
|
27 Each integer pair must be in the form ``m-n`` where m & n are integers
|
bgneal@64
|
28 between 0 and 6, inclusive. Each integer represents a lug position where
|
bgneal@64
|
29 0 is a neutral position, and 1-6 correspond to key wheel positions. If
|
bgneal@64
|
30 m & n are both non-zero, they cannot be equal.
|
bgneal@64
|
31
|
bgneal@64
|
32 If a string has less than 27 pairs, it is assumed all remaining bars have both
|
bgneal@64
|
33 lugs in the neutral (0) positions.
|
bgneal@64
|
34
|
bgneal@64
|
35 Order of the pairs within the string does not matter.
|
bgneal@64
|
36
|
bgneal@64
|
37 To reduce typing and to aid in readability, an alternate shortcut notation is
|
bgneal@64
|
38 supported::
|
bgneal@64
|
39
|
bgneal@64
|
40 lugs = '1-0 2-0*2 0-3 0-5*3 0-6 2-4 3-6'
|
bgneal@64
|
41
|
bgneal@64
|
42 Any pair that is suffixed by ``*k``, where k is a positive integer, means there
|
bgneal@64
|
43 are ``k`` copies of the preceeding lug pair combination. For example, these two
|
bgneal@64
|
44 strings describe identical drum configurations::
|
bgneal@64
|
45
|
bgneal@64
|
46 lugs1 = '2-4 2-4 2-4 0-1 0-1'
|
bgneal@64
|
47 lugs2 = '2-4*3 0-1*2'
|
bgneal@64
|
48
|
bgneal@64
|
49 Key wheel pin settings
|
bgneal@64
|
50 ~~~~~~~~~~~~~~~~~~~~~~
|
bgneal@64
|
51
|
bgneal@64
|
52 Key wheel pin settings are represented as iterables of letters whose pins are
|
bgneal@64
|
53 slid to the "effective" position (to the right). Letters not appearing in this
|
bgneal@64
|
54 sequence are considered to be in the "ineffective" position (to the left). If
|
bgneal@64
|
55 None or empty, all pins are set to be ineffective.
|
bgneal@64
|
56
|
bgneal@64
|
57 Examples::
|
bgneal@64
|
58
|
bgneal@64
|
59 all_ineffective = ''
|
bgneal@64
|
60 wheel1 = 'ABDEFHIJMQSUXZ'
|
bgneal@64
|
61 wheel2 = 'EINPQRTVXZ'
|
bgneal@64
|
62 wheel3 = 'DEFGIKNOSUX'
|
bgneal@64
|
63 wheel4 = 'BFGJKRS'
|
bgneal@64
|
64 wheel5 = 'ABCDFGHIJMPS'
|
bgneal@64
|
65 wheel6 = 'ADEFHIJKN'
|
bgneal@64
|
66
|
bgneal@64
|
67 Key list example
|
bgneal@64
|
68 ~~~~~~~~~~~~~~~~
|
bgneal@64
|
69
|
bgneal@64
|
70 An example of using the :class:`~m209.keylist.KeyList` is:
|
bgneal@64
|
71
|
bgneal@64
|
72 .. code-block:: python
|
bgneal@64
|
73
|
bgneal@64
|
74 from m209.keylist import KeyList
|
bgneal@64
|
75
|
bgneal@64
|
76 key_list1 = KeyList(
|
bgneal@64
|
77 indicator='AA',
|
bgneal@64
|
78 lugs='0-4 0-5*4 0-6*6 1-0*5 1-2 1-5*4 3-0*3 3-4 3-6 5-6',
|
bgneal@64
|
79 pin_list=[
|
bgneal@64
|
80 'FGIKOPRSUVWYZ',
|
bgneal@64
|
81 'DFGKLMOTUY',
|
bgneal@64
|
82 'ADEFGIORTUVX',
|
bgneal@64
|
83 'ACFGHILMRSU',
|
bgneal@64
|
84 'BCDEFJKLPS',
|
bgneal@64
|
85 'EFGHIJLMNP'
|
bgneal@64
|
86 ],
|
bgneal@64
|
87 letter_check='QLRRN TPTFU TRPTN MWQTV JLIJE J')
|
bgneal@64
|
88
|
bgneal@64
|
89 Key list file I/O
|
bgneal@64
|
90 ~~~~~~~~~~~~~~~~~
|
bgneal@64
|
91
|
bgneal@64
|
92 Key lists can be stored in files in config file ("INI") style format using
|
bgneal@64
|
93 functions found in the ``m209.keylist.config`` module.
|
bgneal@64
|
94
|
bgneal@64
|
95 .. function:: m209.keylist.config.read_key_list(fname[, indicator=None])
|
bgneal@64
|
96
|
bgneal@64
|
97 Reads key list information from the file given by ``fname``.
|
bgneal@64
|
98
|
bgneal@64
|
99 Searches the config file for the key list with the given indicator. If
|
bgneal@64
|
100 found, returns a :class:`~m209.keylist.KeyList` object. Returns ``None`` if
|
bgneal@64
|
101 not found.
|
bgneal@64
|
102
|
bgneal@64
|
103 If ``indicator`` is ``None``, a key list is chosen from the file at random.
|
bgneal@64
|
104
|
bgneal@64
|
105 .. function:: m209.keylist.config.write(fname, key_lists)
|
bgneal@64
|
106
|
bgneal@64
|
107 Writes the key lists to the file named ``fname`` in config file format.
|
bgneal@64
|
108
|
bgneal@64
|
109 ``key_lists`` must be an iterable of :class:`~m209.keylist.KeyList` objects.
|
bgneal@64
|
110
|
bgneal@64
|
111 Key list file format
|
bgneal@64
|
112 ++++++++++++++++++++
|
bgneal@64
|
113
|
bgneal@64
|
114 An example key list file in config file format is presented below. The label
|
bgneal@64
|
115 for each section of the file is the key list indicator.
|
bgneal@64
|
116
|
bgneal@64
|
117 ::
|
bgneal@64
|
118
|
bgneal@64
|
119 [CA]
|
bgneal@64
|
120 lugs = 0-5*5 0-6*2 1-0*7 1-2 1-3*3 1-6 2-0 3-0*3 3-5*2 3-6 4-5
|
bgneal@64
|
121 wheel1 = ABCDFGHJLOPRVWYZ
|
bgneal@64
|
122 wheel2 = BCDEIJKPQSUVX
|
bgneal@64
|
123 wheel3 = ACDGLNQRSTUV
|
bgneal@64
|
124 wheel4 = FGHIJNQRSU
|
bgneal@64
|
125 wheel5 = DEIJOQS
|
bgneal@64
|
126 wheel6 = BCDEILMNOP
|
bgneal@64
|
127 check = RGPRO RTYOO TWYSN GXTPF PNWIH P
|
bgneal@64
|
128
|
bgneal@64
|
129 [CD]
|
bgneal@64
|
130 lugs = 0-4*4 0-5 1-0*7 1-2*2 1-4*3 2-0*2 2-4*2 2-6*2 3-0*4
|
bgneal@64
|
131 wheel1 = AEFHIKMPQRSUVZ
|
bgneal@64
|
132 wheel2 = ABFGHINORSUVZ
|
bgneal@64
|
133 wheel3 = BDEHJKLMNOQRSU
|
bgneal@64
|
134 wheel4 = CDEFGHJKMRU
|
bgneal@64
|
135 wheel5 = FGHIJOQS
|
bgneal@64
|
136 wheel6 = EGIJKLP
|
bgneal@64
|
137 check = ZRLWL YRMIZ RZOPN UWMVZ DVGPM H
|
bgneal@64
|
138
|
bgneal@64
|
139 Generating key lists
|
bgneal@64
|
140 ~~~~~~~~~~~~~~~~~~~~
|
bgneal@64
|
141
|
bgneal@64
|
142 The ``m209`` library contains a function to pseudo-randomly generate a key list
|
bgneal@64
|
143 that is based on the procedure described in the 1944 M-209 manual.
|
bgneal@64
|
144
|
bgneal@64
|
145 .. function:: m209.keylist.generate.generate_key_list(indicator[, lug_selection=None, max_lug_attempts=MAX_LUG_ATTEMPTS, max_pin_attempts=MAX_PIN_ATTEMPTS])
|
bgneal@64
|
146
|
bgneal@64
|
147 The only required parameter is ``indicator``, the two-letter indicator for
|
bgneal@64
|
148 the key list.
|
bgneal@64
|
149
|
bgneal@64
|
150 If successful, a :class:`~m209.keylist.KeyList` object is returned.
|
bgneal@64
|
151
|
bgneal@64
|
152 If a :class:`~m209.keylist.KeyList` could not be generated
|
bgneal@64
|
153 a ``KeyListGenError`` exception is raised.
|
bgneal@64
|
154
|
bgneal@64
|
155 The algorithm is heuristic-based and makes random decisions based upon the
|
bgneal@64
|
156 1944 procedure. The actual procedure is loosely specified in the manual, and
|
bgneal@64
|
157 much is left up to the human operator. It is possible that the algorithm
|
bgneal@64
|
158 cannot find a solution to meet the key list requirements specified in the
|
bgneal@64
|
159 manual, in which case it simply tries again up to some set of limits. These
|
bgneal@64
|
160 limits can be tweaked using the optional parameters to the algorithm. If no
|
bgneal@64
|
161 solution is found after exhausting the limits, a ``KeyListGenError`` is
|
bgneal@64
|
162 raised.
|
bgneal@64
|
163
|
bgneal@64
|
164 The optional parameters are:
|
bgneal@64
|
165
|
bgneal@64
|
166 * ``lug_selection`` - a list of 6 integers used to drive the lug settings
|
bgneal@64
|
167 portion of the algorithm. If not supplied, a list of 6 integers is chosen
|
bgneal@64
|
168 from data tables that appear in the 1944 manual. For more information on
|
bgneal@64
|
169 the requirements for these integers, see the manual.
|
bgneal@64
|
170
|
bgneal@64
|
171 * ``max_lug_attempts`` - the maximum number of times to attempt to create
|
bgneal@64
|
172 lug settings before giving up
|
bgneal@64
|
173
|
bgneal@64
|
174 * ``max_pin_attempts`` - the maximum number of times to attempt to generate
|
bgneal@64
|
175 key wheel pin settings before giving up
|
bgneal@64
|
176
|