In the CodeHS assignment 8.3.8: Create Your Own Encoding , you are tasked with developing a custom text encoding scheme to represent uppercase letters (A-Z) and the space character using binary. Assignment Requirements Your scheme must be able to represent: Every capital letter A-Z (26 characters). The space character (1 character). Minimal Bits : You must use as few bits as possible for each character. Course Hero Key Logic: Determining the Bit Count To determine how many bits are needed, use the formula 2 to the n-th power is the number of bits. 2 to the fourth power
CHACEfunction encode(message) var encodedMessage = ""; for (var i = 0; i < message.length; i++) var charCode = message.charCodeAt(i); if (charCode >= 65 && charCode <= 90) // Uppercase letters var encodedCharCode = (charCode - 65 + 3) % 26 + 65; else if (charCode >= 97 && charCode <= 122) // Lowercase letters var encodedCharCode = (charCode - 97 + 3) % 26 + 97; else // Non-alphabet characters var encodedCharCode = charCode; 83 8 create your own encoding codehs answers exclusive
msg = "hello world" encoded = encode(msg) decoded = decode(encoded) print("Original:", msg) print("Encoded: ", encoded) print("Decoded: ", decoded) In the CodeHS assignment 8
# Example usage message = "Hello, World!" encoded = encode(message) decoded = decode(encoded) The decoded message: CHACE The pattern used to