{ "info": { "author": "Brian Neal", "author_email": "bgneal@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta", "Environment :: Console", "Intended Audience :: Developers", "Intended Audience :: Education", "Intended Audience :: End Users/Desktop", "Intended Audience :: Information Technology", "Intended Audience :: Other Audience", "Intended Audience :: Science/Research", "License :: OSI Approved :: MIT License", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", "Topic :: Communications", "Topic :: Security", "Topic :: Security :: Cryptography", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules", "Topic :: Utilities" ], "description": "======\nPurple\n======\n\nA historically accurate PURPLE simulator written in Python 3\n------------------------------------------------------------\n\n:Author: Brian Neal \n:Version: 0.1\n:Date: February 17, 2013\n:Home Page: https://bitbucket.org/bgneal/purple/\n:License: MIT License (see LICENSE.txt)\n:Documentation: This file\n:Support: https://bitbucket.org/bgneal/purple/issues\n\n``Purple`` is a Python library and command-line utility for simulating the\n`PURPLE Machine`_, a cipher machine used by the Japanese Foreign Office before\nand during the Second World War. PURPLE was the code name given to the machine\nby U.S. cryptanalysts. The Japanese called the machine *97-shiki \u014dbun inji-ki*\n(System 97 Printing Machine for European Characters), and *Ang\u014dki B-kata* (Type\nB Cipher Machine). The machine was used for secure diplomatic communications\nand was implemented as an electromechanical stepping-switch device.\n\nThis project is a Python 3 library and command-line utility for encrypting and\ndecrypting text by simulating the operation of an actual PURPLE machine.\n\nIf you are brand new to the ``Purple`` cipher machine, please skip down to the\nreferences section and familiarize yourself with the device. This will help you\nunderstand the terminology used in the documentation, below.\n\n\nRequirements\n############\n\n``Purple`` was written in Python_ 3, specifically 3.3.2, and has no other external\ndependencies.\n\n\nInstallation\n############\n\n``Purple`` is available on the `Python Package Index`_ (PyPI). There are\na number of ways to install to ``Purple``, detailed below. The author\nrecommends you install into a virtualenv_. Setting up a virtualenv is not hard,\nbut describing it is out of scope for this document. Please see the virtualenv_\ndocumentation for more information.\n\nYou can install it using pip_::\n\n $ pip install purple # install\n $ pip install --upgrade purple # upgrade\n\nYou can also visit the the `Purple Bitbucket page`_ and download an archive\nfile of the latest code. Alternatively, if you use Mercurial_, you can clone\nthe repository with the following command::\n\n $ hg clone https://bitbucket.org/bgneal/purple\n\nIf you did not use pip_ (you downloaded or cloned the code yourself), you can\ninstall with::\n\n $ cd where-you-extracted-purple\n $ python setup.py install\n\nTo run the unit tests::\n\n $ cd where-you-extracted-purple\n $ python -m unittest discover\n\n\nInitial Settings Syntax\n#######################\n\nIn order to exchange messages, each message recipient must use the same initial\nmachine settings. For the ``Purple`` machine, these settings are the initial\nswitch positions for the \"sixes\" and three \"twenties\" stepping switches, the\nswitch motion order (which twenties switch is the fast switch, which is the\nmiddle switch, and which is the slow switch), and finally the plugboard\nalphabet mapping.\n\nThe ``Purple`` simulation uses the following syntax in both its command-line\napplication and library code.\n\nFor the switches, we borrow the notation used by U.S. cryptanalysts, for\nexample::\n\n 9-1,24,6-23\n\nHere the first number before leading dash, 9, indicates the starting position\nof the sixes switch. The next three numbers are the starting positions for the\nthree twenties switches numbered 1, 2, and 3. Each switch position is a number\nfrom 1 through 25, inclusive. Finally, after the last dash are two digits which\nindicate the switch stepping motion. The first number, in this case 2,\nindicates that the twenties switch #2 is the fast switch. The second number, 3,\nindicates twenties switch #3 is the middle switch. Thus the slow switch, which\nis never listed, is in this case twenties switch #1. When using this syntax, do\nnot insert space characters.\n\nThe plugboard alphabet setting describes how the input typewriters are wired to\nthe plugboard. We represent this setting as a string of the 26 uppercase\nalphabet letters where the first six letters are the wiring to the sixes\nswitch, and the remaining 20 are wired to the first stage of the twenties\nswitches. For example::\n\n AEIOUYBCDFGHJKLMNPQRSTVWXZ\n\nFor the alphabet setting to be valid, do not insert spaces, and ensure all 26\nletters are used exactly once.\n\n\nCommand-line Usage\n##################\n\nTo get help on the command-line ``Purple`` utility, execute the ``purple``\ncommand with the ``--help`` option::\n\n $ purple --help\n usage: purple [-h] [-e] [-d] [-f] [-s SWITCHES] [-a ALPHABET] [-t TEXT]\n [-i FILE] [-g N] [-w N]\n\n PURPLE cipher machine simulator\n\n optional arguments:\n -h, --help show this help message and exit\n -e, --encrypt perform an encrypt operation\n -d, --decrypt perform a decrypt operation\n -f, --filter filter plaintext and provide useful substitutions\n -s SWITCHES, --switches SWITCHES\n switch settings, e.g. 9-1,24,6-23\n -a ALPHABET, --alphabet ALPHABET\n plugboard wiring string, 26-letters; e.g.\n AEIOUYBCDFGHJKLMNPQRSTVWXZ\n -t TEXT, --text TEXT input text to encrypt/decrypt\n -i FILE, --input FILE\n file to read input text from, - for stdin\n -g N, --group N if non-zero, group output in N-letter groups [default:\n 5]\n -w N, --width N wrap output text to N letters; a value of 0 means do\n not wrap [default: 70]\n\n Supply either -e or -d, but not both, to perform either an encrypt or decrypt.\n If the -s option is not supplied, the value of the environment variable\n PURPLE97_SWITCHES will be used. If the -a option is not supplied, the value of\n the environment variable PURPLE97_ALPHABET will be used. Input text is\n supplied either by the -t or by the -f options, but not both.\n\nThe ``purple`` command operates in two modes, either encrypt (specified with\n``-e`` or ``--encrypt``) or decrypt (``-d`` or ``--decrypt``). Input text can\nbe specified on the command-line with the ``-t`` or ``--text`` option, or\na read from a file (``-i`` or ``--input``).\n\nThe ``-s`` (or ``--switches``) and ``-a`` (or ``--alphabet``) settings\ndetermine the initial machine settings. They use the syntax described above in\nthe Initial Settings Syntax section.\n\nIf you are going to be working with the same initial switch settings and\nplugboard alphabet over many command invocations it may be more convenient to\nspecify them as environment variables instead of repeatedly using the\ncommand-line arguments. The examples below assume these statements have been\nexecuted::\n\n $ export PURPLE97_SWITCHES=9-1,24,6-23\n $ export PURPLE97_ALPHABET=NOKTYUXEQLHBRMPDICJASVWGZF\n\nIf you do not specify initial settings, the ``purple`` machine will attempt to\nread them from these two environment variables. Failing that, ``purple`` will\nuse the following initial settings:\n\n* default switch settings: 1-1,1,1-12\n* default alphabet: AEIOUYBCDFGHJKLMNPQRSTVWXZ\n\nWhen encrypting text, the ``purple`` machine only accepts the letters A-Z, but\nalso allows for \"garble\" letters to be indicated by using the ``-`` (dash)\ncharacter. This means all punctuation and spaces must be either be omitted or\ninput via some other convention. The ``-f`` or ``--filter`` flag, when present,\nrelaxes these restrictions a bit. When this flag is on, all lowercase letters\nwill be converted to uppercase, digits will be converted to words (e.g.\n5 becomes FIVE), and all other characters will be ignored.\n\nA simple encrypt example using the ``-f`` flag is given below::\n\n $ purple --encrypt -t \"The PURPLE machine is now online\" -f\n OGIVT SIAAH MWMHT VIBYY JUOJF UE\n\nBy default ``purple`` prints the output in 5-letter groups. This can be\ndisabled or customized with the ``--group`` and ``--width`` options.\n\nTo decrypt this message::\n\n $ purple --decrypt -t \"OGIVT SIAAH MWMHT VIBYY JUOJF UE\"\n THEPU RPLEM ACHIN EISNO WONLI NE\n\nNote that spaces are ignored on input. Again the output is produced in 5-letter\ngroups and wrapped at 70 letters per line. Here is the output again with\ngrouping disabled::\n\n $ purple -d -t \"OGIVT SIAAH MWMHT VIBYY JUOJF UE\" -g 0\n THEPURPLEMACHINEISNOWONLINE\n\nYou can use file redirection to capture output in a file::\n\n $ purple -e -t \"The PURPLE machine is now online\" -f > secret.txt\n $ purple -d -i secret.txt\n THEPU RPLEM ACHIN EISNO WONLI NE\n\n\nLibrary Usage\n#############\n\nTo use ``Purple`` from within Python code you must first construct\na ``Purple97`` object, which represents a single PURPLE cipher machine. The\nconstructor is given below::\n\n class Purple97(switches_pos=None, fast_switch=1, middle_switch=2,\n alphabet=None)\n\nThe ``switches_pos`` argument, when not ``None``, must be a 4-tuple or list of\n4 integers that describe the initial switch positions. Element 0 is the sixes\ninitial position, and the remaining elements are the initial positions of the\nthree twenties switches. These values must be in the range 0-24, inclusive.\nIf ``None`` then switch positions of all zeroes is assumed.\n\nThe ``fast_switch`` argument indicates which twenties switch (numbered 1-3) is\nthe fast switch. Likewise, ``middle_switch`` indicates which switch is the\nmiddle switch. The slow switch is inferred. It is an error to give the\n``fast_switch`` and ``middle_switch`` arguments the same value.\n\nThe ``alphabet`` argument is the plugboard alphabet mapping. It is expected to\nbe a 26-letter uppercase string. If ``None``, a mapping of\n``AEIOUYBCDFGHJKLMNPQRSTVWXZ`` is assumed.\n\nFor convenience, another constructor is provided that allows you to specify\ninitial settings in the syntax described above::\n\n classmethod Purple97.from_key_sheet(switches, alphabet=None)\n\nHere ``switches`` is a string in the syntax described above, e.g.\n``'9-1,24,6-23'``.\n\nThe ``alphabet`` argument is as described in the first constructor.\n\nOnce constructed, you can use the ``Purple97`` object to perform encrypt and\ndecrypt operations. For example::\n\n from purple.machine import Purple97\n\n purple = Purple97.from_key_sheet(\n switches='9-1,24,6-23',\n alphabet='NOKTYUXEQLHBRMPDICJASVWGZF')\n\n ciphertext = purple.encrypt('THEPURPLEMACHINEISONLINE')\n\n purple = Purple97([8, 0, 23, 5], fast_switch=2, middle_switch=3,\n alphabet='NOKTYUXEQLHBRMPDICJASVWGZF')\n\n plaintext = purple.decrypt(ciphertext)\n\nFor more information, please review the docstrings in the code.\n\n\nSupport\n#######\n\nTo report a bug or suggest a feature, please use the issue tracker at the\n`Purple Bitbucket page`_. You can also email the author using the address at\nthe top of this file.\n\n\nReferences\n##########\n\n#. *PURPLE Revealed: Simulation and Computer-aided Cryptanalysis of Angooki\n Taipu B*, by Wes Freeman, Geoff Sullivan, and Frode Weierud. This paper\n was published in Cryptologia, Volume 27, Issue 1, January, 2003, pp. 1-43.\n#. Frode Weierud's CryptoCellar page: `The PURPLE Machine`_\n#. Wikipedia Article: `PURPLE Machine`_\n\nThe paper in reference 1 is also available here:\nhttp://cryptocellar.web.cern.ch/cryptocellar/pubs/PurpleRevealed.pdf\n\nThis simulator would not have been possible without Frode Weierud's\nCryptoCellar page and the detailed explanations and analysis found in reference\n1. The author is also deeply grateful for email discussions with Frode Weierud\nand Geoff Sullivan who provided me with plaintext, advice, and encouragement.\n\nThe ``Purple`` simulator's operation was checked against the simulator found in\nreference 2.\n\n\n.. _PURPLE Machine: http://en.wikipedia.org/wiki/Purple_(cipher_machine)\n.. _Python: http://www.python.org\n.. _Python Package Index: http://pypi.python.org/pypi/purple/\n.. _virtualenv: http://www.virtualenv.org/\n.. _pip: http://www.pip-installer.org\n.. _Purple Bitbucket page: https://bitbucket.org/bgneal/purple/\n.. _Mercurial: http://mercurial.selenic.com/\n.. _The PURPLE Machine: http://cryptocellar.web.cern.ch/cryptocellar/simula/purple/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://bitbucket.org/bgneal/purple/", "keywords": null, "license": "MIT", "maintainer": null, "maintainer_email": null, "name": "purple", "package_url": "https://pypi.org/project/purple/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/purple/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://bitbucket.org/bgneal/purple/" }, "release_url": "https://pypi.org/project/purple/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Simulation of the WW2 Japanese PURPLE cipher machine.", "version": "0.1.0" }, "last_serial": 1005609, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "56b221bd7d2d62e06ee3dbdf44c1312b", "sha256": "b231062a900578b7f844be17d25da1b86aa61b6546390b6541dd12ee6032c084" }, "downloads": -1, "filename": "purple-0.1.0.tar.gz", "has_sig": false, "md5_digest": "56b221bd7d2d62e06ee3dbdf44c1312b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22012, "upload_time": "2014-02-20T01:10:00", "url": "https://files.pythonhosted.org/packages/70/0d/712c0f0d7859f30bc13f64760a2c637ed22c9ed67c7fbe70e7c0c87eaa8d/purple-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "56b221bd7d2d62e06ee3dbdf44c1312b", "sha256": "b231062a900578b7f844be17d25da1b86aa61b6546390b6541dd12ee6032c084" }, "downloads": -1, "filename": "purple-0.1.0.tar.gz", "has_sig": false, "md5_digest": "56b221bd7d2d62e06ee3dbdf44c1312b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 22012, "upload_time": "2014-02-20T01:10:00", "url": "https://files.pythonhosted.org/packages/70/0d/712c0f0d7859f30bc13f64760a2c637ed22c9ed67c7fbe70e7c0c87eaa8d/purple-0.1.0.tar.gz" } ] }