This is an encryption algorithm inspired by the ``Solitaire'' algorithm (aka Pontifex) from The Cryptonomicon. After reading that book, I wanted to try out Solitaire, but I found it a pain to do all that counting and adding modulo 26. I tend to be absent minded, and thus have problems with both of these things (adding and counting).
So I decided to try to come up with a simpler card based encryption method, which hopefully will be just as secure. As a caveat, I am not a cryptologist, and have no idea whether the following algorithm is secure. However I am a physicist, and have some experience with random number generators. Specifically, I have been burned by the bad random number generator in the first edition of Numerical Recipes.
My encryption algorithm, Nicias2, does not require addition or subtraction, or even counting above seven. I had hoped to limit myself to counting to five, but that resulted in a clearly insecure algorithm, as I will discuss later.
I wanted to make my algorithm entirely reversible for two reasons. First, I read somewhere that this is a good idea, although I didn't really understand why. Secondly, this way if you make a mistake you may be able to reverse your tracks and redo it correctly.
Thirdly, it made it easier to test my algorithms by hand. I could encrypt
a few letters with my deck in a known state and then reverse the process.
If it returned to its original state I knew I had done it right. If not I
had made a mistake. If I made mistakes too often, I knew the algorithm was
too complex. One version required counting to nine, and that was too
much. I don't know what mistakes I made, but I made them often enough to
get very annoyed with myself.
You can create a random deck in this order easily by simply taking a well shuffled deck and shifting the cards until they reach this order. Or, if that sounds complicated, you could sort out the red and black cards (keeping their order the same) and then reintegrate them.
Each black card corresponds to a cleartext character (since `black and
white' means clear, sort of) and each red card represents a ciphertext
character. Table 2.1 gives the correspondences of characters to
cards.
|
A deck fashioned in this order provides a simple mapping from cleartext to ciphertext. You just find the black card corresponding to your cleartext, and the red card on top of it tells you the ciphertext. This is quite easy to do (that being the theme of this whole scheme).
The above method would provide a simple (and simple to crack) encryption scheme. What we need to do is to change the deck between each encryption in a manner that is hopefully indistinguishable from random. This requires some deck manipulations. In the following two sections I will describe the four deck manipulations I use.
Actually, I define two cut-swaps. There is a red card on the top of the deck, so when you are told to cut-swap a red card, you cut above it and swap it with the former top card of the deck. There is a black card on the bottom of the deck, so you cut-swap a black card by cutting underneath it and then swapping it with the cormer bottom card of the deck.
This may sound a bit complicated, but it is actually very easy to do. It takes just a little while to get the hang of it, and then you can do it very reliably.
The transpose gets its name, because if your deck is a one dimensional array, then this operation corresponds to treating the first nxm cards as an nxm matrix and then transposing this matrix (into a mxn matrix) and reversing its order.
If you don't follow that, don't worry. It is an easy way for me to think about the operation, because I have worked with matrices and are familiar with how they are laid out in memory. This has helped me to understand the operation, but it may not help you.
The transpose nxm is reversed by the transpose mxn operation. When I first started working on this I used a transpose 7x7, which is its own inverse. This is convenient and elegant, but has the downside that even with cutswaps in between, the transposes tended to reverse themselves. It was so bad that I could see that it was insecure just by doing it by hand, without using the computer!
The shuffle proceeds as follows:
Perhaps I should define poor behavior. My primary guide in developing this system (once I had developed the deck manipulations by hand) was the self correlation function when encrypting just one character again and again. For a good encryption method this character stream should be indistinguishable from random.
For more details on the analysis I used to try to ensure there were no correlations, see the last chapter.
Originally (not counting the miserable 7x7 which didn't require a
computer to tell me it was messed up) I used a 3x17 transpose
followed by a 3x3 transpose. This seemed like a nice idea, and
only involved counting to three. Unfortunately, I found that often the
same character could reappear after three characters. I tried many
combinations looking at how often the same character would reappear after
any number of characters. For a random sequence, the probability should
always be
. I found that for my sequences this value was often as
low as
. This was not good. Eventually I found that the above
sequence of primes is good.
Unfortunately, even using four different primes is not enough. It is important to have just the right cutting. A small change in the above cutswapping sequence can have drastic effects on the randomness of the encrypted sequence. This is why all the other manipulations are in there (even down to the silly sliggle).
Moral of the story: I had to be very careful. Each operation interacts with the others, and can have unforseen consequences. One algorithm looked perfect, until a few hundered thousand characters into the sequence it started suddenly repeating itself. That was bad.
Other moral of the story: quite likely there is a hidden correlation in my cryptosystem which I am ignorant of (since I am ignorant of so much), and so I can't guarantee that it is any good. That is also why I'm putting it on the web, since I would love to have someone else find a problem with it so I could learn more.
There are many ways to deal with keys, but I'm not going to discuss them. I will just suggest one way to deal with it. I don't know if it is secure, but it may be, and it is reasonably convenient.
You start out with shared decks, plus two shared passwords. Before encrypting or decrypting, you encrypt the first password (but don't transmit the result!). This means that even if someone copied your deck, they will still have to guess your password in order to decode your message. After encrypting (or decrypting) you then encode your second password. This is necesary because the algorithm is reversible. If anyone steals your deck after you've encoded with it, and also intercepts your transmission, they could decode it. But first they'd have to guess your second password. To really be secure, your passwords would have to be long and random.
The convenience of this method comes along when you want to encrypt your second message. As long as the first message was received and decrypted successfully, you and your friend once again share identical decks. So you can encrypt another message using your two passwords again. Probably it would be best to have two decks each, one for encryption and one for decryption, since if both parties try to encrypt simultaneously with the same deck, it would be a pain to sort it out.
To the best of my knowledge, this algorithm is secure, but since my knowledge is pathetically limited, that isn't saying much.
SOCRATES: Come on then, Nicias, your friends are floundering in a sea of words! We've got ourselves hopelessly confused, so you'd better give us some help, if there's anything you can do.Nicias (the algorithm) may not help you out of any philosophical difficulties, but it may be able to make plaintext out of your ciphertext.
I also looked at the breakdown given the location in the deck at which the black cleartext card was located in the first place. This was intended to guide me as to where any problems might lie.
Thirdly, I considered different simple cleartext. One was all the same character (a), another two alternating characters (ab), and the third was three characters rotating (abc).
Of course, in each case we have to collect enough statistics to give a
meaninful result, as determined by Poisson statistics. This can take quite
a while, thanks to the
convergence, but such is life.
Without further ado, here are my correlations:
(a): Correlation 1 2 3 4 5 6 7 8 9 10 11 12 13 error Location 0: 2.7 -2.2 -0.3 -1.2 -0.9 -0.9 2.0 -0.5 -0.1 0.0 -0.6 -0.4 -1.4 +- 0.7 Location 1: -2.0 -4.2 1.9 -0.9 0.5 0.5 -1.1 0.0 -0.3 0.1 -0.3 -0.9 0.6 +- 0.7 Location 2: 1.5 7.2 -0.6 0.6 0.0 -1.2 0.2 -0.9 0.3 -0.4 -0.4 -0.5 -0.9 +- 0.7 Location 3: 1.1 -8.8 -1.9 0.4 0.6 1.4 0.1 -0.4 -0.1 -0.3 1.2 -0.2 0.6 +- 0.7 Location 4: 1.0 -7.6 -5.1 -0.2 0.6 0.4 -0.1 0.1 0.5 -0.5 -0.3 -0.2 0.4 +- 0.7 Location 5: 1.3 -3.5 -0.7 1.0 -0.2 -1.7 -0.3 0.5 -0.5 0.3 0.0 -0.1 -0.6 +- 0.7 Location 6: -3.0 -2.9 -2.4 0.2 0.2 0.2 -0.0 1.3 -1.0 -0.0 1.4 0.1 -1.5 +- 0.7 Location 7: 2.1 22.4 -3.8 1.2 0.4 -0.1 0.0 0.7 -0.2 0.7 0.6 0.4 -0.3 +- 0.7 Location 8: 0.9 1.6 3.5 0.5 0.6 -0.7 -1.1 -0.4 0.4 -0.5 0.1 0.1 0.2 +- 0.7 Location 9: -0.1 -6.2 -2.6 0.6 -0.6 -0.3 0.4 -0.2 0.5 0.7 -1.3 0.1 0.7 +- 0.7 Location 10: 0.6 -2.8 -2.3 0.2 0.2 -0.4 0.7 0.0 0.5 -0.6 0.5 -0.3 -0.9 +- 0.7 Location 11: 1.6 -4.7 0.4 -0.6 1.1 -0.2 -0.5 -0.5 0.1 0.9 0.4 0.6 0.3 +- 0.7 Location 12: 0.8 -7.2 -0.3 -0.7 0.1 0.2 0.7 0.0 -0.1 0.5 0.6 -1.0 0.8 +- 0.7 Location 13: 1.5 7.2 -1.8 0.9 -0.1 -0.3 -0.3 1.5 -0.9 0.2 -0.5 -0.7 0.1 +- 0.7 Location 14: 1.3 18.7 -2.1 -0.6 0.3 -0.6 0.3 0.4 0.6 1.0 -0.0 -0.5 0.9 +- 0.7 Location 15: 2.1 7.0 2.5 -0.3 1.2 -0.0 0.3 -1.0 -0.2 1.4 -0.0 1.4 -0.4 +- 0.7 Location 16: 1.6 13.1 1.7 0.9 0.4 -0.2 -1.3 -0.6 -0.0 -0.1 -1.4 -0.2 -0.2 +- 0.7 Location 17: 2.1 -8.3 -0.9 1.4 1.2 0.1 -0.5 -0.6 -0.7 -1.3 0.3 0.9 1.0 +- 0.7 Location 18: 1.2 -5.7 -1.4 -0.6 0.1 0.2 -0.7 0.4 -0.9 -0.4 0.4 0.4 -1.1 +- 0.7 Location 19: 1.5 6.6 -1.6 -0.6 0.4 1.0 0.1 0.1 -0.6 -1.0 0.2 -0.0 -0.9 +- 0.7 Location 20: 1.2 -7.2 0.2 -0.3 1.3 0.9 0.3 0.9 0.2 -0.4 0.9 0.4 1.4 +- 0.7 Location 21: 0.9 -5.0 -0.4 0.1 -0.3 1.2 0.6 0.5 -0.5 -0.1 0.1 0.2 -0.8 +- 0.7 Location 22: 0.2 3.0 0.4 0.2 -1.2 -0.5 0.4 -0.1 -0.3 -0.4 1.0 -0.8 1.1 +- 0.7 Location 23: 0.5 -5.6 -2.9 0.3 -0.3 1.9 0.1 0.9 0.3 -0.2 -0.5 -0.2 -0.5 +- 0.7 Location 24: -3.0 -10.9 -1.2 -0.5 0.1 0.4 0.8 -0.9 -0.2 1.8 0.0 0.5 0.3 +- 0.7 Location 25: 0.6 2.0 -2.1 1.9 -0.4 0.9 -0.2 0.2 0.0 -0.2 0.4 -0.8 -0.6 +- 0.7 Total : 0.78 -0.16 -0.91 0.15 0.21 0.08 0.03 0.06 0.13 0.05 0.10 -0.06 -0.07 +- 0.13 (ab): Correlation 1 2 3 4 5 6 7 8 9 10 11 12 13 error Location 0: -0.6 -0.1 2.4 0.6 -0.5 0.3 0.3 -0.2 -0.9 0.7 0.3 0.4 -0.5 +- 0.6 Location 1: 3.2 29.8 -0.9 -1.0 0.5 -0.0 -0.3 0.1 -0.3 -0.4 -0.8 -0.4 -0.1 +- 0.6 Location 2: 0.1 -3.0 -1.6 0.1 -0.3 -0.7 1.2 -0.1 0.1 0.9 -0.3 -0.1 1.5 +- 0.6 Location 3: 0.2 -1.4 -0.5 0.3 1.1 -0.6 0.2 -0.5 -0.2 0.0 0.0 0.1 -0.2 +- 0.6 Location 4: 0.5 -4.0 3.8 -0.4 0.5 1.0 -0.0 -0.5 -0.3 -0.7 -0.6 0.6 -0.3 +- 0.6 Location 5: -0.5 -3.9 0.6 -0.1 -0.4 -0.3 -1.2 -0.5 -0.1 0.3 0.6 -0.3 0.0 +- 0.6 Location 6: -0.6 -1.2 -0.5 -0.5 0.5 -0.2 0.0 0.3 -0.4 -0.7 -0.3 -0.9 0.9 +- 0.6 Location 7: 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 0.2 -0.2 -0.3 0.2 -0.6 -0.3 -0.4 +- 0.6 Location 22: -0.0 -1.9 0.6 0.5 0.1 -0.0 1.2 0.0 0.7 -0.6 -0.6 -1.0 0.6 +- 0.6 Location 23: -0.8 -3.0 -0.7 0.0 0.1 0.1 -0.1 0.2 -0.4 0.6 -0.3 0.0 -0.4 +- 0.6 Location 24: 1.7 -2.6 -2.1 -0.2 -0.3 0.3 0.6 -0.3 -0.2 -1.0 0.1 -0.1 0.3 +- 0.6 Location 25: 0.1 -2.7 -1.9 -0.0 -0.2 -0.0 0.2 1.1 -0.4 0.8 -0.2 0.0 -0.2 +- 0.6 Total : 0.09 -1.13 -0.27 -0.23 0.19 -0.07 0.03 -0.10 0.03 0.19 -0.02 -0.20 -0.02 +- 0.11 (abc): Correlation 1 2 3 4 5 6 7 8 9 10 11 12 13 error Location 0: 0.6 -1.7 0.4 0.2 0.1 0.6 -1.2 -0.7 0.3 -0.1 1.0 -0.0 0.4 +- 0.8 Location 1: 2.9 -0.5 4.9 0.4 0.3 -1.2 1.5 0.8 -0.2 1.4 0.4 -0.5 0.9 +- 0.8 Location 2: -0.6 -0.1 1.8 0.4 -0.3 -0.7 -1.6 0.3 0.3 -0.4 1.2 -0.8 -0.9 +- 0.8 Location 3: -1.1 -0.2 0.7 0.4 -0.1 0.1 -0.8 0.7 0.2 1.2 -0.5 0.1 -0.6 +- 0.8 Location 4: -0.2 1.0 0.2 -0.9 -0.0 -0.5 -0.8 -0.9 0.7 0.4 -0.7 1.3 1.0 +- 0.8 Location 5: -0.0 -0.8 0.2 0.7 1.1 0.6 -1.1 -0.1 0.1 -0.2 0.0 1.0 -0.8 +- 0.8 Location 6: -0.4 -1.4 -0.3 -0.4 1.2 1.1 1.7 -0.4 0.3 -1.4 -0.2 -0.1 1.2 +- 0.8 Location 7: 0.8 -0.0 -0.2 0.0 1.2 1.0 0.6 -0.4 -0.4 -0.0 1.2 -0.1 0.4 +- 0.8 Location 8: 0.1 -1.4 -0.4 -1.2 0.3 -0.4 1.4 2.6 -0.4 -1.0 0.2 1.0 1.1 +- 0.8 Location 9: -1.2 -0.2 -0.3 -0.7 0.4 -0.2 1.2 0.2 -0.1 0.8 -0.6 -0.3 0.3 +- 0.8 Location 10: -0.3 1.1 -0.3 -0.5 0.3 -0.2 0.2 -0.5 0.7 0.2 0.7 -0.4 -1.8 +- 0.8 Location 11: 1.8 0.6 0.5 0.6 0.9 -0.1 -0.5 0.9 -0.5 -1.1 0.4 0.6 -0.5 +- 0.8 Location 12: 0.3 -0.3 -0.5 0.4 0.1 0.7 -0.4 -0.7 0.1 -1.1 -1.1 0.1 0.8 +- 0.8 Location 13: -1.0 -0.6 -0.8 1.1 0.2 0.2 0.9 2.4 1.2 -1.0 -2.1 0.1 -0.5 +- 0.8 Location 14: -1.5 -0.5 -0.3 0.9 -0.2 1.3 -1.3 -0.2 0.8 -0.8 -0.1 -0.5 1.3 +- 0.8 Location 15: 0.0 -0.4 -0.3 -0.1 1.1 0.1 0.5 -0.1 1.5 -0.5 -1.6 -0.6 -0.1 +- 0.8 Location 16: -1.0 -1.4 1.0 0.1 -0.6 -0.7 -0.8 0.0 -0.4 -1.5 0.9 0.3 -0.5 +- 0.8 Location 17: 0.1 0.0 0.9 -1.7 1.2 -0.2 0.4 -1.3 0.0 0.5 -0.5 1.1 0.3 +- 0.8 Location 18: 1.0 2.0 -0.6 -0.9 -0.0 -0.3 0.0 -0.5 0.1 -0.3 -0.3 -0.1 -0.6 +- 0.8 Location 19: 0.1 -0.8 -1.3 1.2 0.0 2.4 0.5 0.4 -0.6 0.2 -1.0 0.2 -0.4 +- 0.8 Location 20: -0.1 0.6 -1.2 -0.9 0.6 0.3 0.1 -0.5 0.5 -0.4 1.1 -0.5 -0.0 +- 0.8 Location 21: -0.3 -0.5 -1.1 -0.3 0.2 0.2 -0.0 0.8 1.0 0.0 0.5 0.3 0.7 +- 0.8 Location 22: -0.3 0.5 -1.1 -0.1 -0.0 1.1 -1.2 -0.4 0.8 -0.3 -1.0 0.0 -0.8 +- 0.8 Location 23: 0.2 0.9 -1.1 -0.4 0.1 0.7 -0.1 0.9 -1.3 0.4 -0.7 -0.7 -0.8 +- 0.8 Location 24: 1.5 0.4 0.4 0.5 -1.1 0.3 0.2 -1.4 0.1 0.8 -0.3 -0.6 -0.2 +- 0.8 Location 25: -0.7 0.7 0.9 1.4 -0.2 -0.1 1.3 -1.3 -0.8 0.1 0.6 1.2 -0.7 +- 0.8 Total : 0.03 -0.11 0.08 0.01 0.25 0.23 0.03 0.03 0.15 -0.15 -0.10 0.08 -0.03 +- 0.15
The correlations are given in percent of the expected probability. So a correlation of -100% would mean that the character never appears, while a correlation of 2500% would be the maximum value, corresponding to the character always repeating. The standard deviation is given on the far right.
If you can't understand the format, you can email me to ask, or you can look at the code used to generate them:
The conclusion is that my worst correlations are about 1%, which happens when words like ``dada'' are encrypted. There is a similar correlation in the case of the encryption of repeated characters. The output when encrypting the ``abcabc'' sequence is consistent with a random sequence.
This seems pretty good to me, but I'm afraid I don't have much experience with encryption schemes, so it may not be. If you have any insights into this question, I would very much like to hear from you.