We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

State Ciphers

Stream ciphers are also referred to as "state ciphers" because the encryption and decryption of each character depends on the current state of the cipher.

"Current state" just means the "current progress", that is, how many bytes we've already encrypted or decrypted so far.

For example, let's take the following data for a one-time pad cipher:

plaintext = "010011"
key       = "101001"

When the "state" of the cipher is at index 0, we will only have encrypted the first digit:

plaintext = "010011"
key       = "101001"

state     = index 0
result    = "1"

state     = index 1
result    = "11"

state     = index 2
result    = "111"

state     = index 3
result    = "1110"

state     = index 4
result    = "11101"

state     = index 5
result    = "111010"

Assignment

We've been asked to update our code to print the progress of the cipher as it encrypts and decrypts each character. There have been some very large encryption tasks, and people are getting confused when the cipher doesn't seem to be doing anything for a while.

Update the crypt function. It should print this message after each character is sent to the result channel:

Crypted byte: NUM

Where NUM is the number of bytes that have been encrypted so far, starting at 1.