Fix: 8.3 8 Create Your Own Encoding Codehs Answers

: This acts as our custom encoding dictionary. It swaps standard vowels and the letter 's' with "Leet Speak" numbers.

Use the alphabet index (a=1, b=2… z=26) plus special codes for space (27), period (28), etc.

Original: Hello World Encoded: U8 U5 U12 U12 O15 _ U23 O15 U18 U12 U4 Decoded: Hello World

: Web browsers cannot transmit spaces or special characters reliably within a URL. Browsers run custom encoding functions to turn spaces into %20 and exclamation marks into %21 .

To create an encoding program, you need to manipulate strings at a character level. Python offers two primary methods for this: 8.3 8 create your own encoding codehs answers

Example of run-length plus custom encoding:

Need more help? Check the CodeHS documentation on dictionaries or ask your instructor for clarification on the specific requirements of your version of 8.3.8.

For instance, if you type HELLO WORLD using the 5-bit mapping above, verify that the autograder generates the exact matching sequence: 00111 00100 01100 01100 01111 11010 10110 01111 10010 01100 00011

# 3. Process each character for char in message.upper(): # Convert to uppercase for simplicity if char in encoding_map: result += encoding_map[char] + " " # Add a space between each byte else: # Handle spaces or unsupported characters # You could skip them or map them to a special pattern pass : This acts as our custom encoding dictionary

def encode(message): """Encodes a plaintext message using the custom scheme.""" enc_dict = build_encoding_dict() result_parts = [] for ch in message: if ch in enc_dict: result_parts.append(enc_dict[ch]) else: # If character not in dict, keep as is result_parts.append(ch) # Join with a space to separate tokens for easy decoding return ' '.join(result_parts)

Match the exact text requested by the assignment description inside your input() function. Extra spaces or missing colons can trigger a grading error.

The exercise on CodeHS challenges you to apply everything you have learned about binary and character encoding in a creative, hands‑on way. Whether you choose a straightforward fixed‑width encoding or a more efficient variable‑width design, the key is to define clear mappings and implement both encoding and decoding functions carefully.

def decode(nums): rev = 1:'a', 2:'b', 3:'c', 0:' ' return ''.join(rev[n] for n in nums) Original: Hello World Encoded: U8 U5 U12 U12

print(f"Plain Text: plain_text") print(f"Encoded Text: encoded") print(f"Decoded Text: decoded")

At its core, this exercise requires you to build a custom protocol that converts plain text into a binary representation—and back again. To do so, you'll need to write two core functions:

Use the charCodeAt() and String.fromCharCode() methods in JavaScript (or similar functions in Python) to shift the numerical value of the character.

This assignment is more than a programming exercise; it teaches critical computer‑science concepts:

result = "" for ch in text.upper(): if ch == " ": result += "27" else if ch == ".": result += "28" else: result += format(ord(ch) - ord('A') + 1, width=2, pad='0') return result

: Process every character in the string through a custom encoding loop.