# Doug's MATLAB Video Tutorials

## Schneier’s solitaire cipher

I have liked cryptography since I was sending Caesar cipher messages to my fellow 6th graders. The essence of that was to ‘add’ a value to each letter of your message. With Caesar, it was a constant value. With a one time pad they are pattern-less values, but they have to be stored. With Bruce’s algorithm, the values to be added to your message are generated by an algorithm. Know the starting state of the algorithm, and you can generate the values, or keystream. All the security lies in the ‘key’ or starting state. Since this algorithm works on a deck of cards, there are factorial(54) starting states. That is a lot. The example below will only use a six card deck.

In some ways, this is a lot like a pseudo-random number generator: The values are only random to the uninitiated. In this series, we will implement the algorithm, and analyze the output of the algorithm.

The algorithm will rearrange the cards. Since for a six card problem, there are 720 states for the cards to be in we can say for certainty that after 721 iterations, we will have repeated a state. The question is does it take that long, or are their smaller loops? How many loops or cycles are there?

Here is the Cody problem, so watch the video to see the algorithm and try to implement it.

 Name (required) E-mail (required, will not be published) Website (optional) Spam protection (required): What is 4 + 6 ?

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>


If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

These postings are the author's and don't necessarily represent the opinions of MathWorks.