Home  |  Site Map
  ConceptDevelopment.NET
Skip Navigation Links
Home
SearchExpand Search
SilverlightExpand Silverlight
DatabaseExpand Database
ValidationExpand Validation
LocalizationExpand Localization
Fun stuffExpand Fun stuff
  Download now

ZIP file (35k) [18th August 2002] This ZIP file (35k) contains a the C# code and HTML for the algorithm and this site. It needs to be in a virtual directory 'Pontifex' on your web server.


About the code
Some of the code is based on the Java code available from CounterPane. The Deck class implements the IEnumerable interface in C#.
It was built using the Microsoft VisualStudio.NET Release Candidate on Windows 2000 and Internet Explorer 6.0.

  About Solitaire (a.k.a. Pontifex)
August 2002

C# implementation of the Solitaire algorithm from CounterPane and featured in Neal Stephenson's book Cryptonomicon.

The code consists of the following classes:

   PontifexSolitaire exposes Encrypt() and Decrypt() methods that use the Deck and Card classes to perform the Solitaire algorithm on text strings
Deck class to model behaviour of cards in a deck, with methods specific to the requirements of the Solitaire algorithm (such as CutTop(), MoveDown(), TripleCut()...)
Card struct to model a card
CardFace enum [ Ace | Two ... Ten | Jack | Queen | King ]
CardSuit enum [ Hearts | Clubs | Diamonds | Spades | Joker ]

This implementation is by no means the fastest, most efficient version of the Solitaire algorithm; however I hope it's still interesting. The design using Card and Deck objects is intended to make the code easy to read and understand (and validate the algorithm logic against the text at CounterPane).

The results from Counterpane's Solitaire test vectors are also available to check.

You can test encrypt/decrypt strings using this implementation, and check the results with Carumba.org's Perl CGI implementation.

Finally, the Deck implementation provides a ToHtml() function (in addition to ToString()) function which allows Deck testing. There's really no great benefit to this, other than while constructing the algorithm it was possible to test in parallel with a real deck of cards, and visually check the results.

[Update 3rd March 2004]
Eli Robillard has blogged his (much nicer) C# Implementation of the Solitaire (aka Pontifex) Encryption Algorithm which is definitely worth a look.

Useful links

TRY IT OUT!
Encrypt and decrypt using Solitaire C# !

GotDotNet.com QuickStart
Read the .NET sample code, where I found the pieces for implementing IEnumerable.

CounterPane
Bruce Schneier of CounterPane is the designer of the Solitaire algorithm.

Carumba.org
A Perl implementation that you can try online.

Cryptonomicon
The book where I first read about Solitaire. Great book (other Stephenson books are also recommended).