Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In each round we will begin with a deck of cards placed on top of each other with some order. The steps for one round

image text in transcribedimage text in transcribed

In each round we will begin with a deck of cards placed on top of each other with some order. The steps for one round of the keystream value generation algorithm for processing an English message are as follows: 1. Find the small joker in the deck. (The small joker is the card with the second highest value, which is 27 in our context for English alphabet.) Swap this card with the card that is directly under it in the deck, so that the small joker moves down one position. If the small joker was found to be at the bottom of the deck, then instead swap the small joker with the card at the top of the whole deck. It may help to think of the deck as being circular so that the card "under" the bottom card is the top card. 2. Find the big joker in the deck. (The big joker is the card with the highest value, which is 28 in our context for the English alphabet.) Move the big joker two cards down the deck by performing two card swaps. As before, think of the deck as being circular. 3. Recall that the two cards with the highest two values are the two jokers. Call the joker closer to the top of the deck the first joker, and the one closer to the bottom the second joker. (Note this is independent of which is the big or small joker.) Swap the stack of cards above the first joker with the stack of cards below the second joker. This is called a triple cut. What happens if a joker is at the top or bottom of the deck? What if the jokers are next to each other? Is this a problem? 4. Look at the value on the bottom card in the deck. Let's represent the value of the bottom card by the symbol v. If the bottom card is the big joker, take v to be the value of the small joker instead. (In our example with English, if the bottom card is 28, use v= 27 instead.) Then, take the group of v cards from the top of the deck, and insert that group just above the bottom card in the deck. 5. Look at the value on the top card in the deck. Let's represent the value of that top card by the symbol w. If w is the big joker, take w to be the value of the small joker instead. (Again, in our example with English, if the value on the top card is 28, use w = 27 instead.) Starting from the top, find the card that is at index w in the deck. If the card at position w is a joker, continue the current round back at Step 1. Otherwise, remember the value on the card at position w in the deck - it is the keystream value generated for the current round. This keystream value will be in the range of 1 to the size of the deck minus two, inclusive (1 to 26 in our example with English). Why can't it be a joker? The parameter represents a valid deck of cards. get_card_at_top_index (List[int]) -> int This is Step 5 of the algorithm. Using the value of the top card as an index, return the card in the deck at that index. Special case: if the top card is the big joker, use the value of the small joker as the index. The parameter represents a valid deck of cards. get_next_keystream_value (List[int]) -> int Repeat all five steps of the algorithm until a valid keystream value is produced, then return that valid keystream value. The first parameter represents a valid deck of cards. The second represents a list of messages. The third parameter is either ENCRYPT or DECRYPT the constants defined at the top of file cipher_functions.py . process_messages (List[int], List[str], str) -> List[str] Return a list of encrypted messages if the third parameter is ENCRYPT or decrypted messages if the third parameter is DECRYPT . The messages are returned in the same order as they are given. Note that the first parameter may also be mutated during a function call

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

d. What language(s) did they speak?

Answered: 1 week ago