Mercurial > public > pelican-blog
comparison content/Coding/024-m209.rst @ 4:7ce6393e6d30
Adding converted blog posts from old blog.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Thu, 30 Jan 2014 21:45:03 -0600 |
parents | |
children | 6e0d4799796d |
comparison
equal
deleted
inserted
replaced
3:c3115da3ff73 | 4:7ce6393e6d30 |
---|---|
1 Introducing m209 | |
2 ################ | |
3 | |
4 :date: 2013-08-01 20:05 | |
5 :tags: Python, m209, Enigma | |
6 :slug: introducing-m209 | |
7 :author: Brian Neal | |
8 | |
9 I'm very pleased to announce yet another M-209_ simulator written in Python, | |
10 creatively called m209_. Last summer I worked on Enigma_ simulators in both | |
11 `Python <http://py-enigma.readthedocs.org/en/latest/>`_ and `C++ | |
12 <https://bitbucket.org/bgneal/cpp-enigma>`_, and I thought it would be fun to | |
13 try another World War II-era crypto device. m209_ is a Python 3 library and | |
14 command-line utility for encrypting and decrypting text by simulating the | |
15 operation of an actual M-209_ device. | |
16 | |
17 One fun part about doing something like this is researching the original | |
18 device. It seems like there are more resources online about the M-209_ than the | |
19 Enigma_. I even found an actual 1940's War Department training film on YouTube | |
20 that explains how to operate the M-209_, including the procedure for encrypting | |
21 and decrypting messages! I want to thank `Mark J. Blair`_ for his very | |
22 informative pages on the M-209_ which were very helpful to me. Check out the | |
23 `m209 references section <https://m209.readthedocs.org/en/latest/#references>`_ | |
24 for these and other useful links. | |
25 | |
26 The M-209_ isn't as complex as the Enigma_. That isn't meant to knock it. The | |
27 M-209_, while cryptographically not as secure as the Enigma_, is a remarkable | |
28 piece of mechanical engineering. It is much more portable and easier to | |
29 operate compared to the Enigma_. It has user-friendly features like printing to | |
30 paper tape and a letter counter for backing up when mistakes are made. | |
31 According to Wikipedia, about 140,000 of these machines were produced. They | |
32 even come up on eBay a few times a year, and seem to go for between $1000 | |
33 - $2000 USD. Maybe someday I can score an actual unit! | |
34 | |
35 Coding the actual simulator wasn't all that hard. I spent much more time on | |
36 the unit tests, documentation, and creating an application to generate key | |
37 lists. Writing the documentation gave me some good practice with Sphinx_, an | |
38 awesome Python based documentation tool that uses the `reStructured Text`_ | |
39 markup language. | |
40 | |
41 Writing the key list generator was actually the hardest part. The procedure for | |
42 creating key lists is spelled out in a M-209 manual from 1944 (which exists | |
43 online as a series of photos). The procedure is kind of loosely specified, and | |
44 a lot is left up to the soldier creating the key list. I came up with an | |
45 ad-hoc, heuristic-based algorithm that works most of the time. If it got stuck | |
46 it simply started over, and retried up to a certain number of attempts. | |
47 | |
48 While researching the procedure, I noticed what appears to be a typo in the | |
49 data tables in the manual that are used when developing a key list. On top of | |
50 that I found several sets of initial numbers that I could not generate a key | |
51 list from. In other words, using these starting numbers, my algorithm could not | |
52 generate M-209 settings that satisfied the exit criteria for the procedure in | |
53 the manual. After a while, I just removed those troublesome initial conditions | |
54 as possible inputs. It would be interesting to return to this some day and | |
55 write a program to search the solution space exhaustively to see if there | |
56 really was a solution for these numbers. It could just be that my | |
57 trial-and-error algorithm could not find a solution, even after tens of | |
58 thousands of attempts. However this doesn't seem likely. I wonder if these | |
59 initial settings caused lots of head scratching for the poor officer trying to | |
60 create a key list. | |
61 | |
62 In any event, if you are into this kind of thing, I hope you check out m209_. | |
63 Doing a project like this is a lot of fun. I enjoy doing the research, creating | |
64 the code, and working on the test suite. I also get some practice with Python | |
65 packaging and writing documentation with Sphinx. | |
66 | |
67 Future enhancements include adding the ability to read Mark Blair's key lists | |
68 that he created for his C++ simulator. This would make it easier for our two | |
69 simulators to interoperate. | |
70 | |
71 Links: | |
72 | |
73 * `m209 documentation <http://m209.readthedocs.org>`_ | |
74 * `m209 on PyPi <https://pypi.python.org/pypi/m209>`_ | |
75 * `m209 source code repository on Bitbucket <https://bitbucket.org/bgneal/m209/>`_ | |
76 | |
77 .. _M-209: http://en.wikipedia.org/wiki/M-209 | |
78 .. _m209: http://m209.readthedocs.org/ | |
79 .. _Enigma: https://en.wikipedia.org/wiki/Enigma_machine | |
80 .. _Mark J. Blair: http://www.nf6x.net/groups/m209group/ | |
81 .. _Sphinx: http://sphinx-doc.org/index.html | |
82 .. _reStructured Text: http://docutils.sf.net/rst.html |