Mercurial > public > pelican-blog
view content/Coding/024-m209.rst @ 20:137650a0be4e
Add requirements.txt.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 27 Aug 2016 13:04:58 -0500 |
parents | 6e0d4799796d |
children |
line wrap: on
line source
Introducing m209 ################ :date: 2013-08-01 20:05 :tags: Python, m209, Enigma, simulator :slug: introducing-m209 :author: Brian Neal I'm very pleased to announce yet another M-209_ simulator written in Python, creatively called m209_. Last summer I worked on Enigma_ simulators in both `Python <http://py-enigma.readthedocs.org/en/latest/>`_ and `C++ <https://bitbucket.org/bgneal/cpp-enigma>`_, and I thought it would be fun to try another World War II-era crypto device. m209_ is a Python 3 library and command-line utility for encrypting and decrypting text by simulating the operation of an actual M-209_ device. One fun part about doing something like this is researching the original device. It seems like there are more resources online about the M-209_ than the Enigma_. I even found an actual 1940's War Department training film on YouTube that explains how to operate the M-209_, including the procedure for encrypting and decrypting messages! I want to thank `Mark J. Blair`_ for his very informative pages on the M-209_ which were very helpful to me. Check out the `m209 references section <https://m209.readthedocs.org/en/latest/#references>`_ for these and other useful links. The M-209_ isn't as complex as the Enigma_. That isn't meant to knock it. The M-209_, while cryptographically not as secure as the Enigma_, is a remarkable piece of mechanical engineering. It is much more portable and easier to operate compared to the Enigma_. It has user-friendly features like printing to paper tape and a letter counter for backing up when mistakes are made. According to Wikipedia, about 140,000 of these machines were produced. They even come up on eBay a few times a year, and seem to go for between $1000 - $2000 USD. Maybe someday I can score an actual unit! Coding the actual simulator wasn't all that hard. I spent much more time on the unit tests, documentation, and creating an application to generate key lists. Writing the documentation gave me some good practice with Sphinx_, an awesome Python based documentation tool that uses the `reStructured Text`_ markup language. Writing the key list generator was actually the hardest part. The procedure for creating key lists is spelled out in a M-209 manual from 1944 (which exists online as a series of photos). The procedure is kind of loosely specified, and a lot is left up to the soldier creating the key list. I came up with an ad-hoc, heuristic-based algorithm that works most of the time. If it got stuck it simply started over, and retried up to a certain number of attempts. While researching the procedure, I noticed what appears to be a typo in the data tables in the manual that are used when developing a key list. On top of that I found several sets of initial numbers that I could not generate a key list from. In other words, using these starting numbers, my algorithm could not generate M-209 settings that satisfied the exit criteria for the procedure in the manual. After a while, I just removed those troublesome initial conditions as possible inputs. It would be interesting to return to this some day and write a program to search the solution space exhaustively to see if there really was a solution for these numbers. It could just be that my trial-and-error algorithm could not find a solution, even after tens of thousands of attempts. However this doesn't seem likely. I wonder if these initial settings caused lots of head scratching for the poor officer trying to create a key list. In any event, if you are into this kind of thing, I hope you check out m209_. Doing a project like this is a lot of fun. I enjoy doing the research, creating the code, and working on the test suite. I also get some practice with Python packaging and writing documentation with Sphinx. Future enhancements include adding the ability to read Mark Blair's key lists that he created for his C++ simulator. This would make it easier for our two simulators to interoperate. Links: * `m209 documentation <http://m209.readthedocs.org>`_ * `m209 on PyPi <https://pypi.python.org/pypi/m209>`_ * `m209 source code repository on Bitbucket <https://bitbucket.org/bgneal/m209/>`_ .. _M-209: http://en.wikipedia.org/wiki/M-209 .. _m209: http://m209.readthedocs.org/ .. _Enigma: https://en.wikipedia.org/wiki/Enigma_machine .. _Mark J. Blair: http://www.nf6x.net/groups/m209group/ .. _Sphinx: http://sphinx-doc.org/index.html .. _reStructured Text: http://docutils.sf.net/rst.html