Using Classical Ciphers with pycipher

To learn some of the concepts and approaches used by current encryption algorithms (ciphers), it can be useful to first study how some of the original, simpler ciphers work (e.g. Caesar cipher, Playfair, Vigenere). With these simpler ciphers, often referred to as classical ciphers, it is quite easy to understand the algorithm and even perform encryption/decryption by hand. Athlough most are trivial to break with computers today, the concepts they use are often applied in current day ciphers.

Selected classical ciphers are studied in my security courses: Security and Cryptography and IT Security. Although it is valuable to initially perform the encryption steps by hand, sometimes its useful to use software to speed things up. pycipher is a Python package that implements many classical ciphers. It has good documentation on how to use it, including installation instructions. Below I give two alternatives to install pycipher in a virtnet node running Ubuntu 12.04.5 LTS. The first is the default and easiest that uses git. The second is an alternative if git is not available and you want a specific version of pycipher.

Install pycipher (Recommended Method)

In a terminal on the virtual node run:

network@node1:~$ sudo apt-get update
network@node1:~$ sudo apt-get install git python-pip
network@node1:~$ sudo pip install git+git://github.com/jameslyons/pycipher

Install pycipher (Alternative Method)

If the recommended method above does not work (e.g. you don't have or want to use git or pip), then you could try the following:

network@node1:~$ sudo apt-get install unzip python-setuptools
network@node1:~$ wget https://github.com/jameslyons/pycipher/archive/master.zip
network@node1:~$ unzip master.zip 
network@node1:~$ cd pycipher-master/
network@node1:~/pycipher-master$ sudo python setup.py install
network@node1:~/pycipher-master$ python setup.py test

This installs and tests the latest version. Depending on the version, some tests my fail. In my case it ran 41 tests, but 2 tests failed (using the Porta algorithm). Do not use the algorithms that failed the tests.

Using pycipher

A quick example of encrypting and decrypting with pycipher is below. Other ciphers include: Beaufort, Foursquare, Enigma, Polybius, Bifid, ADFGVX, Coltrans, Playfair, and Vigenere. Details on the ciphers supported and how to use them are in the latest documentation.


network@node1:~$ python
Python 2.7.3 (default, Feb 27 2014, 20:00:17) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import pycipher
>>> pycipher.Caesar(3).encipher("hello")
'KHOOR'
>>> pycipher.Caesar(3).decipher("khoor")
'HELLO'
>>> quit()