Feb 192009
 

After I added an M-209-B Converter to my collection, I decided to write a software simulation of it as a learning exercise. Here is the result: a command-line application, written in C++, which is able to encipher and decipher text just like a real M-209 machine does. In addition, my simulator can generate new random keys and automate parts of the message-handling process. I’m releasing my simulator under the GNU Public License in the hope that it may be useful, educational and/or entertaining.

Update: This software is now hosted on GitHub GitLab. See this post for details.

My simulator is not the only one out there. I suggest that you also look at this wonderful graphical M-209 Simulator written by Dirk Rijmenants!

I’ve named my simulator package “hagelin”, with the expectation that I will eventually add simulators for more of Boris Hagelin’s pin-and-lug cipher machine designs. For now, only an M-209 simulator is included in the “suite”. If and when I add more simulators to the package, you’ll still find it at this URL, though the title of this page would then change.


 

System Requirements

The hagelin package is distributed as source code. To build it, you’ll need a fairly recent Unix-like system, a C++ compiler (such as g++), and other common development tools which you probably have if you have the C++ compiler. It may be possible to port the hagelin package to other systems on which a C++ compiler is available.

The hagelin package has been successfully built on the following systems:

 

  • Mac OS X, with the GNU toolchain provided by Fink/FinkCommander or MacPorts.
  • Windows XP, with the GNU toolchain provided by Cygwin.
  • Fedora Core 5 (a rather old Linux distribution).

The Mac environment listed above is my primary development environment for the hagelin project.

It should be possible to build the hagelin project without much trouble on any fairly recent Unix-like system on which the GNU toolchain is available and on which common GNU software packages are easily built.


 Downloading the Software

This software is now hosted on GitHub. See this post for details.

 


 

Compiling and Installing the Software

You compile and install the hagelin package just like most common open-source packages on Unix-like systems:

 

     tar xjvf hagelin-1.2.tar.bz2
     cd hagelin-1.2
     ./configure
     make
     make check
     make install

 

Using the Software

Please refer to the manual page(s) installed as part of the hagelin package, as well as the built-in help that’s available by calling any of the included programs with the “-h” option. For your convenience, here are PDF versions of the included manual pages:


 

Example

Here is an operation example:

 

     ~...hagelin-1.2/samples% ls
     MB.m209key	cipher.txt	deciphered.txt	plain.txt

     ~...hagelin-1.2/samples% m209 -g -p -l AB > AB.m209key

     ~...hagelin-1.2/samples% ls
     AB.m209key MB.m209key cipher.txt deciphered.txt plain.txt

     ~...hagelin-1.2/samples% cat plain.txt
     old password compromised new password is quote aaaaargh dont shoot dont shoot unquote

     ~...hagelin-1.2/samples% m209 -a -c -l AB > mycipher.txt
     Reading from stdin...
     Loading key file ./AB.m209key

     ~...hagelin-1.2/samples% cat mycipher.txt
     UUMEP IKHAB LWRUK ZHYXT GRMVL
     PPNGD UWSRN IBDMI TWIVT YZYNV
     VZYVU XQKYV NPJLD BUHTA YBGMV
     ZHLKO VPVGC HTLFM APMLO UUMEP
     IKHAB

     ~...hagelin-1.2/samples% m209 -a -d < mycipher.txt 
     Reading from stdin...
     Loading key file ./AB.m209key
     OLD PASSWORD COMPROMISED NEW PASSWORD IS QUOTE AAAAARGH DONT SHOOT DONT SHOOT UNQUOTE

 

Bug Reports

If you find any bugs, please let me know.

 

  4 Responses to “M-209 Simulation Software”

  1. Hello, could you decrypt this?

    MMABC DEFYK FOXOJ QZVDR SDCUB AGFIT VMBXC XRZEK PQOIH XKYUB XTVQH XYXTG HWTDU AESZB TMTXW MTGSW VQQDV RKYUN WBBSQ LAQAP JGWQB NEHBW AXUFF HTCYX MMABC DEFYK

    Thank you very much, Larry

  2. Dennis Ritchie, Robert Morris:

    Hagelin M-209 Cyptanalysis from Ciphertext Alone

    https://cryptome.org/2015/12/ReedsTheHagelinCipherBellLabs1978.pdf