A collection of ciphers from the classical era. Inspired by Practical Cryptography.
Unless otherwise noted, the default alphabets for these ciphers is the lowercase English alphabet.
Affine Cipher
A monoalphabetic substitution cipher.
key_a
and the length of the alphabet (26 by default) must be coprime.
from affine import Affine
key_a = 7
key_b = 9
a = Affine(key_a, key_b)
Atbash Cipher
The Atbash cipher is a version of the Affine cipher, using 25 as both key_a
and key_b
from atbash import Atbash
a = Atbash()
Caesar Cipher
A simple substitution cipher using a shift of 3.
from caesar import Caesar
c = Caesar()
Gronsfeld Cipher
A variant of the Vigenère cipher which uses numbers instead of letters for the key.
from gronsfeld import Gronsfeld
key = [1, 2, 3, 4, 5]
g = Gronsfeld(key)
ROT13 Cipher
A simple substitution cipher using a shift of 13.
from rot13 import Rot13
r = Rot13()
Running Key Cipher
A variant of the Vigenère cipher where the key must be longer than the plaintext.
from runningkey import RunningKey
key = "itwasthebestoftimesitwastheworstoftimes"
r = RunningKey(key)
Simple Substitution Cipher
A monoalphabetic substitution cipher which shifts the plaintext by the specified shift
parameter.
from substitution import Substitution
shift_value = 5
s = Substitution(shift_value)
Vigenère Cipher
A monoalphabetic substitution cipher which shifts the plaintext by the specified shift
parameter.
from vigenere import Vigenere
key = "foobar"
v = Vigenere(key)