📜 ⬆️ ⬇️

Crypto Solitaire

The streaming encryption algorithm SOLlTAlRE (PASIANCE) was proposed by B. Schneier in 1999. The cipher is beautiful and I don’t understand why nobody has illuminated it at Habré. Did no one read Stevenson's Kryptonomicon? Actually, after reading the book, I cannot pass by this miracle.

From theory, this is a stream cipher with output feedback. From the threading it follows that each symbol of the original sequence will correspond to an encrypted symbol. For those who do not know, for example, there are still block ciphers, in which encryption occurs in blocks (several bytes or characters). Further, there are many types of clutch blocks of text and the so-called gamma (some random secret sequence). In this case, the output feedback is used, i.e. each gamma symbol changes the gamma state.



Encryption


Encryption is extremely easy. There are 2 sequences:
  1. DO NOT USE PC
  2. AD JEN MWD OI

1 - the text to be encrypted. 2 - gamma (about its generation below). All that is needed is to translate the text into numbers and break the text into 5 letters (this is cryptographic etiquette). If there are less letters, they are filled with a certain conditional symbol, for example, x.
  1. 4 | 15 | 14 | 15 | 20 21 | 19 | 5 | 16 | 3
  2. 1 | 4 | 10 | 5 | 14 13 | 23 | 4 | 15 | 9

Next is the addition. If you get a number greater than 26, then you must subtract 26 from it. Example 4 + 1 = 5, 20 + 14 = 8.
The final sequence: 5 | 19 | 24 | 20 | 8 8 | 16 | 9 | 5 | 12. Translate into letters: ESXTH HPIEL
')
Decryption

Decrypting a message is also very easy. Absolutely the same gamma is generated and gamma is subtracted from the ciphertext. If a number less than zero is obtained, then just 26 is added to it. Example 5-1 = 4, 8-14 = 20.
  1. 5 | 19 | 24 | 20 | 8 8 | 16 | 9 | 5 | 12
  2. 1 | 4 | 10 | 5 | 14 13 | 23 | 4 | 15 | 9

Total we have 4 | 15 | 14 | 15 | 20 21 | 19 | 5 | 16 | 3 -> DO NOT USE PC

Gamma Generation


It is this part of the algorithm that makes this cipher so interesting. A full deck of cards 52 cards + 2 jokers is required. Maps must be numbered, preferably in the mind (you do not want the NSA to know your secret). From Ace to the King from 1 to 13 and according to the colors, the order is the following: Clubs, Diamonds, Worms, Spades. The last 2 numbers will take the joker, which must be distinguished between 53-A, junior joker and 54-B senior joker.
You need to have 2 decks that will be shuffled in exactly the same way. You will have one deck, your friend will have another deck, who will decrypt your messages.
For ease of perception, I will cut decks to 28 cards. Suppose initially they were arranged in this order:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28

1 step. Move the junior joker to 1 card down the deck. If it turns out to be the last one, then place it after 1 card.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 28 27

2 step. Move the high joker 2 positions down the deck. If he is the last, then place him after 2 cards, if he is the last but after the first card.
1 28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

3 step. Swap the 2 ends of the deck, separated by 2 jokers. In this case, the number 1 will go to the end of the deck.
28 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1

4 step. Look at the last number. Count off so many cards from the beginning of the deck and place them before the last card. The last card is intentionally left in place for reversibility of the algorithm.
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 1

5 step. Look at 1 number. Count down the number of cards after it and remember this number. In this case, it is 4. This is the first number of the key sequence. This step does not change the deck. Further steps 1 to 5 are repeated n times. Where n is the number of characters in the encrypted text.

Localization


I also thought about the Cyrillic version of “solitaire”. Everything turned out to be quite not difficult. If we exclude the letter e, then in Russian there are 32 letters. +2 jokers total 34 cards. A regular deck without a 6-approx.

Implementation


The essence of the cipher is in its invisibility. Well, judge for yourself what looks pale: a deck of cards or encryption programs on a laptop? However, it is necessary to spend a lot of time to encrypt and decrypt large texts. I found a whole bunch of implementations . But among them was not familiar to me PHP. It was just a very boring evening and a small application was born (link below). The basis of the application is the solitaire class. It implements some necessary methods.


Evaluation


Such algorithms can only be decrypted by brute force (brute force). Various analytical methods are practically not applicable to it. The weakness of the algorithm is only in its key (deck). If you capture a deck, they will be able to decipher it, provided that you completely follow the algorithm.
The author himself offers several ways.
1. Use each time a new key. Take the key from a certain agreement (a bridge column from newspapers, certain numbers from stock ratings, etc.). The main thing about them to agree.
2. Change the gamma acquisition algorithm slightly. Then, when removing the deck, the NSA still does not understand anything.

Links


Official article of the author of the algorithm: link
My application for encryption and decryption: link
Link to PHP class: link

Source: https://habr.com/ru/post/138986/


All Articles