Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 3 This question will test your knowledge of some of the built-in Python data structures and functions. You're an accomplished cryptoanalyst, charged with writing

image text in transcribed

Question 3 This question will test your knowledge of some of the built-in Python data structures and functions. You're an accomplished cryptoanalyst, charged with writing a method to decode a new cryptographic cipher that was recently identified. The cipher works by taking the original message and injecting a bunch of junk letters into it. Before each letter of real text, the cipher adds a number and a sequence of junk letters. The number corresponds to the number of junk letters that follow; the next letter is part of the original text. For example, take the word "hey" as our original message. This could be encrypted to be the following "Oh2abe1zy". Taking this character by character from left to right: the number "0" indicates that 0 junk characters follow, before a letter from the actual text:"h" Next, we have another number, "2", which indicates 2 junk characters follow "a" and "b" before a letter from the actual text:"e" . Finally, we have the number "1", indicating 1 junk character "z" before a real letter:"y" Now we have reached the end of the encrypted text, and we have recovered our original letters: "h", "e" and "y" (or "hey") Iterating through the text in this way allows us to recover the original text and decode the cipher. Write a function: named decode which takes 1 argument: the encoded string and returns a decoded version of the argument string The only restriction in solving this problem is that you cannot import anything: you must use the base Python library. Hint #1: A loop (For Loop or While Loop would both work but I strongly suggest a using a While Loop) is almost certainly going to be needed. You will use the Loop to loop through the characters in the encoded string and sometimes skipping over arbitrary elements(that's why While loop is easier). Hint #2: If you have a list of characters list_of_chars , you can glue them back into a string object uding the statement s = "".join(list_of_chars). For example, if I have a list chars = ["h", "e", "y"] , I can do msg = "".join(chars) and msg is now 'hey' Hint #3: Pay attention to your data types, is it a string? An integer? A list? For example, remember that "2" is different from 2, the first being a string and the second being an integer number

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

Object Databases The Essentials

Authors: Mary E. S. Loomis

1st Edition

020156341X, 978-0201563412

More Books

Students also viewed these Databases questions