In this assignment, the encryption algorithm we use encrypts (or decrypt) one letter of the message at a time.

First, we will remove all characters that are not letters from the plaintext message and also convert all lowercase letters to uppercase. This means that whitespace, digits and punctuation are lost in the encryption process, leaving only uppercase letters of the alphabet. Next, we convert the letters to numbers based on their place in the alphabet (A is represented as 0, B as 1, C as 2, …, Y as 24, and Z as 25). We’ll use the resulting sequence of these numbers as input to the encryption algorithm.

After the letters are converted to numbers (remember, we’re only converting capital letters here), the encryption algorithm generates a special number for each position in the plaintext message. These special numbers are called keystream values. To encrypt each letter, the numeric letter value and the corresponding keystream value are added, modulo 26, and then the resulting number is converted to its letter form. The two numbers that are added are the number corresponding to the letter in the plaintext, and the keystream value for the position of the letter in the plaintext.

Decryption is just the inverse of encryption. Start by converting the letters in the ciphertext to be decoded to numbers, in the same way as the original plaintext message was converted. Then, use the encryption algorithm again to generate a special number for each position in the ciphertext. Subtract these special numbers from the numbers from the ciphertext, again modulo 26. Finally, convert the resulting numbers to letters to recover the plaintext message.

The only other requirement for the encryption and decryption processes to work is that both encryption and decryption use the same sequence of keystream values. In our algorithm, we’ll use a representation of a deck of playing cards to generate keystream values. The encryption and decryption algorithms need to start with the same decks.