Other/Cipher

Solitaire

파에 2008. 11. 17. 05:05

Encrypting with Solitaire


Solitaire is an output-feedback mode stream cipher. Sometimes this is called key-generator (KG in U.S. military speak). The basic idea is that Solitaire generates a stream, often called a ``keystream,'' of numbers between 1 and 26. To encrypt, generate the same number of keystream letters as plaintext letters. Then add them modulo 26 to plaintext letters, one at a time, to create the ciphertext. To decrypt, generate the same keystream and subtract, modulo 26 from the ciphertext to recover the plaintext. (Don't worry, I'll explain "modulo" in a minute.)

 

For example, to encrypt the first Solitaire message mentioned in Stephenson's novel, "DO NOT USE PC":

 

1. Split the plaintext message into five-character groups. (There is nothing magical about five-character groups; it's just tradition.) Use X's to fill in the last group. So if the message is "DO NOT USE PC" then the plaintext is:

 

 DONOT  USEPC

 

2. Use Solitaire to generate ten keystream letters. (Details are below.) Assume they are:

 

 KDWUP  onOWT

 

3. Convert the plaintext message from letters into numbers, A=1, B=2, etc:

 

 4 15 14 15 20   21 19 5 16 3

 

4. Convert the keystream letters similarly:

 

 11 4 23 21 16   15 14 15 23 20

 

5. Add the plaintext number stream to the keystream numbers, modulo 26. (All this means is, if the sum is more than 26, subtract 26 from the result.) For example, 1+1=2, 26+1=27, and 27-26=1, so 26+1=1.

 

 15 19 11 10 10   10 7 20 13 23

 

6. Convert the numbers back to letters.

 

 OSKJJ  JGTMW

 

If you're really good at this, you can learn to add letters in your head, and just add the letters from steps (1) and (2). It just takes practice. It's easy to remember that A+A=B; remembering that T+Q=K is harder.

 

Decrypting with Solitaire

 

The basic idea is that the receiver generates the same keystream, and then subtracts the keystream letters from the ciphertext letters.

 

1. Take the ciphertext message and put it in five-character groups. (It should already be in this form.)

 

 OSKJJ  JGTMW

 

2. Use Solitaire to generate ten keystream letters. If the receiver uses the same key as the sender, the keystream letters will be the same:

 

 KDWUP  onOWT

 

3. Convert the ciphertext message from letters into numbers:

 

 15 19 11 10 10   10 7 20 13 23

 

4. Convert the keystream letters similarly:

 

 11 4 23 21 16   15 14 15 23 20

 

5. Subtract the keystream numbers from the ciphertext numbers, modulo 26. For example, 22-1=21, 1-22=5. (It's easy. If the first number is less than or equal to the second number, add 26 to the first number before subtracting. So 1-22=? becomes 27-22=5.)

 

 4 15 14 15 20   21 19 5 16 3

 

6. Convert the numbers back to letters.

 

 DONOT  USEPC

 

As you can see, decryption is the same as encryption, except that you subtract the keystream from the ciphertext message.

'Other > Cipher' 카테고리의 다른 글

Venus table  (0) 2010.01.22
memo - 0  (0) 2009.06.25
히에로 클리프  (0) 2008.07.25
the zodiac cipher  (0) 2008.07.17
Tony Sale's Codes and Ciphers  (0) 2008.07.04