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