def plaintext(ciphertext): # 1. Get length of ciphertext msg_len = len(ciphertext) # 2. Create empty buffer decoded_buffer = [] # 3. while index is < cipher_length cipher_idx = 0 while cipher_idx < msg_len: # 4. read skip_length skip_len = int(ciphertext[cipher_idx]) # 5. skip skip_length chars cipher_idx = cipher_idx + skip_len + 1 # 6. append cur_char to buffer decoded_buffer.append(ciphertext[cipher_idx]) # 7. increment cipher_idx cipher_idx = cipher_idx + 1 # 8. return buffer as a string return "".join(decoded_buffer) print plaintext("0h2abe1zy") print plaintext("2xyz") print plaintext("0h2zyi2467")
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question