The Solitaire Encryption Algorithm in Bash
This is Bruce Schneier's Solitaire Encryption Algorithm coded in bash. For portability and efficiency purposes, I only use bash internal commands to write this script. I have tested it in several operating systems such as Linux debian/Ubuntu, Mac OSX 10.6.8, and even in Windows with Cygwin (in order to port bash).
About Solitaire Algorithm (From schneier.com)
In Neal Stephenson's novel Cryptonomicon, the character Enoch Root describes a cryptosystem code-named "Pontifex" to another character named Randy Waterhouse, and later reveals that the steps of the algorithm are intended to be carried out using a deck of playing cards. These two characters go on to exchange several encrypted messages using this system. The system is called "Solitaire" (in the novel, "Pontifex" is a code name intended to temporarily conceal the fact that it employs a deck of cards) and It was designed to allow field agents to communicate securely without having to rely on electronics or having to carry incriminating tools. An agent might be in a situation where he just does not have access to a computer, or may be prosecuted if he has tools for secret communication.
About the Bash implementation
Basically, this script is divided in four main functions:
- Test vectors I have uploaded the test vectors provided in Schneier's web site (see references). The bash script takes both the plaintext and the key of each test vector and performs first and encrypt operation. The resulting ciphertext is then decrypted using the same key. Finally, if the obtained plaintext is equal to the vector's plaintext the test is successful.
- Cipher consistency check
Solitaire is an output-feedback mode stream cipher. Solitaire is a Symmetric cipher, which means that the key used to encrypt is the same key that is needed to obtain the original plaintext. In the Symmetric ciphers definition,
a cipher defined over (k, m, c) is a pair of “efficient” algorithms (E, D) where
E: m,k -> c
D: c,k -> m
k - key space
m - message
c - cipher text
E - encryption algorithm
D - decryption algorithm
The requirement is that the algorithms are consistent (satisfy correctness property). the consistency equation, which all ciphers must satisfy is the following:
The scripts simply verifies this equation in every execution by creating two RANDOM arrays, the key and the message.
You have two different options to run solitaire implementation in bash: Script Execution instructions
- solitaire_bash.sh and external_functions_for_solitaire_bash.sh
To run the script you must grant execution permissions to the user by doing
chmod +x solitaire_bash.sh
chmod +x solitaire_bash_all_in_one.sh
NOTE. It is not neccessary to grant execution permissions to the external functions file.