Skip to main content

German Cipher Machine Command-Line Tool

Project description

Author:

Cory J. Engdahl

Webpage:

http://www.cjengdahl.com

License:

MIT

Description

German Enigma Machine Command-Line Tool (EnigmaI, M1, M2, M3, M4 Models). Replicates the exact functionality of the physical machines used in WWII with an easy to use command-line interface.

Installation

enigma requires the installation of the python3 interpreter. The only third-party package dependency is Click. If you choose to install via pip, Click will be installed as well.

Install with pip:
pip install enigma-cli

The source can be cloned from https://github.com/cjengdahl/Enigma

Configuration

Just like an actual Enigma Machine, the simulated machine must be configured before use. The configuration serves as the ‘key’. The same key is used to encrypt and decrypt text. The setup configurations are stored in a config file, which can be modified through the command line interface. A default configuration is always available, along with a single, modifiable user configuration named ‘User’. It is required that the following items are specified before use:

  • Enigma Model

  • Rotors Used (ID)

  • Rotor Start Postions

  • Rotor Ring Postions

  • Reflector

  • Plugs Inserted In Plugboard

Preferences

In addition to the machine configuration, there are also user preferences that can be set. These include output grouping, newline removal, space handling, space detection, default configuration, state remembrance, and progressbar inclusion.

Detailed preference description:

  • Output grouping groups the output text to the specified number of characters. Historically, messages where separated by a space every five characters. This preference is ignored if the space handling preference is set to ‘keep’ or ‘X’.

  • Newline removal replaces newline characters with a space. This is only applicable to file input, not encrypting directly from standard input.

  • Space handling allows the user to specify if spaces should be kept in the cipher text, removed, or replaced with an “X” before encryption. Historically, it was common to replace spaces with an “X” because the character itself was not commonly used.

  • Space detection goes hand in hand with the space replacement. During the decryption process, if an “X” is found, it is replaced with a space.

  • The default configuration is the configuration that will be loaded automatically every time an enigma command is executed. By default, the “User” configuration is loaded; however, addition configurations can be specified.

  • The enigma can be placed in a state of remembrance. With this enabled, for each character encrypted/decrypted the state of the machine is saved the nexted use (i.e. the rotor positions are saved after use)

  • Lastly, the command line can include a progressbar while encrypting or decrypting to show the elapsed progress)

Usage

enigma [OPTIONS] COMMAND [ARGS]…

Commands are listed as follows:

encrypt <text>

Encrypts text input with Enigma Machine. All input is converted to uppercase and non-alphabetic characters (with the exception of spaces and newline characters) are removed. Text is optional and takes priority over file input.

Alias: decrypt

Options:

-s, --spaces [remove | X | keep]

Set space handling preference

-n, --newlines [True | False]

Include newline characters

-d, --space-detect [True | False]

Convert decrypted Xs to spaces

-g, --group TEXT

Set output letter grouping

-m, --model TEXT

Enigma machine model

-r1, --fast TEXT

Fast rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r2, --middle TEXT

Middle rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r3, --slow TEXT

Slow rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r4, --static TEXT

Static rotor config: (9 for beta, 10 for gamma), position (1-26), and ring setting (1-26)

-r, --reflect [UKW-A | UKW-B | UKW-C | UKW-B_THIN | UKW-C_THIN]

Enigma reflector

-p, --plugs TEXT

Plugs inserted in plugboard (e.g. “AB,XY”)

-c, --select TEXT

Select enigma machine configuration

-u, --update

Overwrite config file with invoked preferences, and options

-k, --remember [True | False]

Remember machine state after encryption

-f, --input FILENAME

Path to input file

-o, --output FILENAME

Path to output file

clear

Clears all users configurations with the exception of ‘Default’ and ‘User’.

delete <configuration>

Deletes specified user configuration. Default and User configs can not be deleted

list <configuration>

Lists the existing user configurations. Lists configuration details if specific configuration provided as an argument

new <configuration>

Options:

-m, --model [EnigmaI | M2 | M3 | M4]

Enigma machine model

-r1, --fast TEXT

Fast rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r2, --middle TEXT

Middle rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r3, --slow TEXT

Slow rotor config: id (1-8) , position (1-26), and ring setting (1-26)

-r4, --static TEXT

Static rotor config: (9 for beta, 10 for gamma), position (1-26), and ring setting (1-26)

-r, --reflect [UKW-A | UKW-B | UKW-C | UKW-B_THIN | UKW-C_THIN]

Enigma reflector

-p, --plugs TEXT

Plugs inserted in plugboard (e.g. “AB,XY”)

pref

Manages the default preferences. Invoked options updates preferences

Options:

-s, --spaces [remove | X | keep]

Set space handling preference

-n, --newlines [True | False]

Include newline characters

-d, --space-detect [True | False]

Convert decrypted Xs to spaces

-g, --group TEXT

Set output letter grouping

-c, --select TEXT

Select enigma machine configuration

-k, --remember [True | False]

Remember machine state after encryption

-p, --progess [True | False]

Show progressbar

reset <configuration>

Resets specified configuration to “Default” settings.

Basic Examples

Create new configuration:

$ enigma new config1 --model M3 --fast 1,2,3 --middle 5,12,23 --slow 2,17,9 --plugs AB,GD,KL,IU --reflect UKW-B

Encrypt from standard input:

$ enigma pref --select config1
$ enigma encrypt "Hello World"

Encrypting  [####################################]  100%
CMQYT PZVTS

Encrypt from file input, keeping spaces:

$ enigma encrypt -f /usr/share/dict/words -o ~/Desktop/demo.txt
Encrypting  [####################################]  100%
$ less ~/Desktop/demo.txt

Y
B
PV
U BW
LEK KW
BBD
LZSO
V DPGRT PS
PWZ SXDJL
KFIRL
RFMNA FT
QGN KMNTC O
BZDJ SQDT
C VXCAP BTQ
.
.
.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

enigma-cli-0.1.3.tar.gz (15.7 kB view details)

Uploaded Source

File details

Details for the file enigma-cli-0.1.3.tar.gz.

File metadata

  • Download URL: enigma-cli-0.1.3.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for enigma-cli-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5e30d0ccf0b792d6d91255745132c086c234816d21f3f3991b89f21318aef603
MD5 7bf5676ab0f8cd5171f2d5d710e9d6e7
BLAKE2b-256 4c38e4fd1e02cb6335d7dbca5a7a767df2fb2c0ae5f37a3aa9d2a82f27273507

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page