annotate content/Coding/024-m209.rst @ 23:e4f02a31925d

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