Skip to main content

A tool to break substitution ciphers

Project description

Build Status Coverage License Black

Substitution Breaker

This project provides a Python implementation for breaking classical substitution ciphers.

More documentation of the project including a detailed description of the CLI and the python API is available as well.

Overview

A substitution cipher is a method of encryption by which the letters of the plaintext are systematically replaced by substitute letters. The receiver deciphers the text by performing an inverse substitution.

The correlation between the letters of the plaintext and the substitute letters is defined by the key.

Example:

Alphabet: ABCDEFGHIJKLMNOPQRSTUVWXYZ
Key:      ZEBRASCDFGHIJKLMNOPQTUVWXY

The letter “A” from the plaintext maps to the cipher text “Z”, “B” to “E”, and so on. Thus the plaintext “flee at once. we are discovered!” is enciphered as “siaa zq lkba. va zoa rfpbluaoar!”

This package provides a CLI which supports the following operations:

  • encoding and decoding a text with a given key

  • breaking a substitution cipher text when the key is unknown (English language)

  • tools for adding support for other languages and/or other alphabets

All the features supported by the CLI are exposed through functions and classes by a Python package.

Installation

This package requires Python3.5 or higher. It can be installed using pip:

$ pip install subbreaker

Basic Usage

For a full documentation of the subbreaker command refer to the documentation here. There you will find also a detailed description how to use the package directly with Python. In the following only some basic examples for using the CLI are given.

The command subbreaker supports several subcommands. To display them type:

$ subbreaker --help

You can get a detailed help on every subcommand by subbreaker <subcommand> --help. And here comes subbreaker in action:

Encoding a clear text…

$ subbreaker encode --key ZEBRASCDFGHIJKLMNOPQTUVWXY --text "flee at once. we are discovered!"
siaa zq lkba. va zoa rfpbluaoar!

…and decoding it back:

$ subbreaker decode --key ZEBRASCDFGHIJKLMNOPQTUVWXY --text "siaa zq lkba. va zoa rfpbluaoar!"
flee at once. we are discovered!

Break a cipher without knowing the key:

$ subbreaker break --lang EN --text \
"Rbo rpktigo vcrb bwucja wj kloj hcjd, km sktpqo, cq rbwr loklgo
> vcgg cjqcqr kj skhcja wgkja wjd rpycja rk ltr rbcjaq cj cr.
> -- Roppy Lpwrsborr"
Key: wisdomabcznghjklfpqrtuvxye
Score: 103.68
Nbr keys tried: 37050
Keys per second: 61850
Execution time (seconds): 0.599
Plaintext:
The trouble with having an open mind, of course, is that people
will insist on coming along and trying to put things in it.
-- Terry Pratchett

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

subbreaker-1.2.0.tar.gz (410.2 kB view hashes)

Uploaded Source

Built Distribution

subbreaker-1.2.0-py3-none-any.whl (411.6 kB view hashes)

Uploaded Python 3

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