Welcome to classicrack’s documentation!

GitHub: https://github.com/starkfire/classicrack/

Current Version: v0.1.0

Python library for implementing and performing cryptanalysis on classical ciphers.

Supported Ciphers

  • Affine
  • Atbash
  • Caesar
  • ROT13

Cryptanalysis

For cracking, cipher implementations have a crack() method. Implementations of some ciphers, such as ROT-13 and Atbash do not have it, since the decode() method already performs the same task.

So far, classicrack can only perform cryptanalysis on ciphers with keyspace weaknesses (e.g. Affine, Caesar). Implementations for other ciphers such as Vigenere might be added soon.

Install

Clone the project on GitHub and install with pip:

git clone https://github.com/starkfire/classicrack/
cd classicrack/
pip install -r requirements.txt

Ciphers

Affine

class classicrack.ciphers.Affine

Affine cipher is a monoalphabetic substitution cipher that uses the following encryption function:

E(x) = (ax + b) mod m

It is decrypted by taking the modular multiplicative inverse inv of the slope value a:

D(x) = inv * (x - b) mod m
crack(text: str)

Cracks an input Affine ciphertext by generating all 312 possible values, and returns plaintext values with acceptable fitness scores.

Parameters:text – input ciphertext
decode(text: str, slope: int, intercept: int)

Deciphers an input Affine ciphertext.

Parameters:
  • text – input ciphertext
  • slope – slope value, which must be coprime with 26
  • intercept – intercept value
encode(text: str, slope: int, intercept: int)

Enciphers an input plaintext using Affine Cipher.

Parameters:
  • text – input plaintext
  • slope – slope value, which must be coprime with 26
  • intercept – intercept value

Caesar

class classicrack.ciphers.Caesar

Caesar Cipher is a monoalphabetic substitution cipher where characters are shifted with a fixed shift value of n mod 26.

crack(text: str)

Cracks an input Caesar ciphertext and returns plaintext values with acceptable fitness scores.

Parameters:text – input plaintext
decode(text: str, shift: int)

Deciphers an input Caesar ciphertext.

Parameters:
  • text – input ciphertext
  • shift – shift value
encode(text: str, shift: int)

Enciphers an input plaintext using Caesar.

Parameters:
  • text – input plaintext
  • shift – shift value

Atbash

class classicrack.ciphers.Atbash

Atbash is a monoalphabetic substitution cipher that is similar to Affine Cipher. Unlike Affine, Atbash takes the following function for encryption and decryption:

E(x) = D(x) = (-x mod m) + 1
decode(text: str)

Decipher an input Atbash ciphertext.

Parameters:text – input ciphertext
encode(text: str)

Encipher an input plaintext using Atbash.

Parameters:text – input plaintext

ROT13

class classicrack.ciphers.ROT13

ROT13 is similar to Caesar Cipher, where each character takes a shift value of 13:

ABCDEFGHIJKLMNOPQRSTUVWXYZ
NOPQRSTUVWXYZABCDEFGHIJKLM
decode(text: str)

Decipher an input ROT-13 ciphertext.

Parameters:text – input ciphertext
encode(text: str)

Encipher an input plaintext using ROT-13.

Parameters:text – input plaintext