Skip to content
English
  • There are no suggestions because the search field is empty.

8.3 8 Create Your Own Encoding Codehs Answers Link

Before looking at solutions, it’s worth asking: why not just use ASCII or UTF-8?

| System | Pros | Cons for this exercise | |--------|------|------------------------| | ASCII | Standard, simple | Boring – no creativity, fixed mapping | | UTF-8 | Handles all languages | Complex for beginners | | Custom encoding | Teaches mapping logic, compression thinking | Not portable outside the exercise |

The real goal of 8.3.8 is abstraction and representation – understanding that all data is just numbers until we assign meaning. 8.3 8 create your own encoding codehs answers

def encode_xor(msg, key=42):
    return [ord(ch) ^ key for ch in msg]
def decode_xor(codes, key=42):
    return ''.join([chr(c ^ key) for c in codes])

This is more “cryptographic” and still reversible.

Before writing code, decide on your custom cipher. Here are three common student approaches: Before looking at solutions, it’s worth asking: why

| Scheme | Rule | Example ('A') | |--------|------|----------------| | Shift Cipher | Add a fixed number to each character’s position | A(0)+3 = 3 | | ASCII-based | Use ord() but modify it (e.g., subtract 30) | 65 → 35 | | Custom Alphabet Map | Create a dictionary: 'A':1, 'B':2,… | 1 |

For CodeHS 8.3.8, the simplest yet “custom” method is to use a shift cipher relative to the ASCII code, but explain it as your own invention. The teacher wants to see that you can map characters to unique integers and back. This is more “cryptographic” and still reversible

  • Decoding rule: Split into 8-bit chunks, convert each chunk from binary to decimal, then to ASCII.

  • The most interesting fact about CodeHS 8.3.8 is that there is no official correct mapping. The autograder only checks that your encoding and decoding are inverses. You could map 'a' to 999 and 'b' to -42 – as long as decode(encode(x)) == x, you pass.

    That creative freedom is the real lesson. Encoding is a contract between writer and reader. Build your contract wisely, document it, and you’ve written not just code, but a tiny data format specification – the first step toward inventing your own file format, protocol, or language.


    Want to see a sample solution for 8.3.8 that passes the autograder with room for creativity? Ask and I can provide one.