Skip to content

ncarusso/Solitaire_bash

Repository files navigation

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:

  1. Encrypt
  2. Decrypt
  3. 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.
  4. 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:

    D(k, E(k,m))=m

    The scripts simply verifies this equation in every execution by creating two RANDOM arrays, the key and the message.

Script Execution instructions

You have two different options to run solitaire implementation in bash:
  • solitaire_bash.sh and external_functions_for_solitaire_bash.sh
  • solitaire_bash_all_in_one.sh
Although both versions behave almost equally, the first version is easier to read because it presents the functions separated from the main body of the script. The external functions are invoked with the bash source command. It is important to notice that both files must be in the same directory for solitaire to be executed.

To run the script you must grant execution permissions to the user by doing

chmod +x solitaire_bash.sh

or

chmod +x solitaire_bash_all_in_one.sh

and then

./solitaire_bash.sh

or

./solitaire_bash_all_in_one.sh

NOTE. It is not neccessary to grant execution permissions to the external functions file.

References

About

Bruce Schneier's Solitaire encryption algorithm coded in bash

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages