Crypto-code "solitaire"

    The algorithm of stream encryption SOLlTAlRE (PASYANS) was proposed by B. Schneier in 1999. The cipher is madly beautiful and I don’t understand why no one has illuminated it yet. Has no one read Stevenson's Cryptonomicon? Actually, after reading the book, I can’t get past this miracle.

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



    Encryption


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

    1 - 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 fewer letters, then they are filled with a certain 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 26 must be subtracted from it. Example 4 + 1 = 5, 20 + 14 = 8.
    The final sequence: 5 | 19 | 24 | 20 | 8 8 | 16 | 9 | 5 | 12. We translate into letters: ESXTH HPIEL

    Decryption

    Decrypting a message is also very easy. The exact same gamma is generated and the gamma is subtracted from the ciphertext. If the result is a number less than zero, then 26 is simply 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 complete deck of cards is required 52 cards + 2 jokers. Cards must be numbered, preferably in the mind (you don’t want the NSA to know your secret). From Ace to King from 1 to 13 and according to suit, the order is as follows: Clubs, Tambourines, Worms, Spades. The last 2 numbers will take the joker, which must be distinguished 53-A, the youngest joker and 54-B senior joker.
    You need to have 2 decks that will be shuffled exactly the same. You will have one deck, another one from your friend who will decrypt your messages.
    For ease of perception, I will reduce the deck 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 1 card down the deck. If it turns out to be the last, put 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 senior joker 2 positions down the deck. If it is the last, then place it after 2 cards, if the penultimate, then 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 extreme parts 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 so many cards from the beginning of the deck and place them in front of the last card. The last card is intentionally left in place for the 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 out so many 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. Next, steps 1 to 5 are repeated n times. Where n is the number of characters in the ciphertext.

    Localization


    I also thought about the Cyrillic version of "solitaire". Everything turned out to be pretty not difficult. If the letter ё is excluded, then 32 letters remain in the Russian language. +2 jokers total 34 cards. Normal deck without 6 app.

    Implementation


    The essence of the cipher is its invisibility. Well, judge for yourself what looks more pale: a deck of cards or encryption programs on a laptop? However, it takes a lot of time to encrypt and decrypt large texts. I found a whole bunch of implementations . But among them there was no PHP familiar to me. It was just a very boring evening and a small application was born (link below). The basis of the application is the class "solitaire". It implements some necessary methods.
    • Preparing a message. determination of its linguistic affiliation, the formation of some constants and string processing.
    • Gamma preparation. More precisely, the initial sequence that the user sets. It just turns out gamma
    • Getting gamma character by character. The solution is probably not the most elegant (I will be glad to comments). Used massive array_slice - array_merge.
    • Convert strings to numbers and vice versa.
    • Addition of lines and subtraction (encryption and decryption).


    Rating


    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 they capture the deck, they can decrypt it, and then, provided that you fully follow the algorithm.
    The author himself offers several ways.
    1. Use a new key each time. Take the key from a certain arrangement (a column of a bridge from newspapers, some numbers from stock ratings, etc.). The main thing is to agree on them.
    2. Slightly change the algorithm for obtaining gamma. Then, when removing the deck, the NSA still does not understand anything.

    References


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

    Also popular now: