CODING
ADVENTURE
0 / 12 completed

CASE 03 / CHAPTER 2

Read Tony's message

Representation, bytes and a library helper

IN THE STORY

Tony's text message represents the next clue as hexadecimal bytes.

The idea

Hexadecimal uses sixteen digit symbols: 0–9 and a–f. A pair can represent a byte. For instance, 41 represents the byte used for the letter A in this example. Python already has a helper to turn hex into bytes: bytes.fromhex. decode("utf-8") interprets those bytes as text. You are using these helpers, not expected to write them. Hex encoding is not secret encryption.

Your mission

Pass the variable message to bytes.fromhex. Keep the supplied decoding step.

Replace ____ with the missing expression, then choose Run code. Match the expected output before trying your own changes.

Before you run it

Why is putting the word "message" in quotes different from using message?

A little help?

Hint 1: a nudge

The clue is stored in a variable. Pass that value to the helper.

Hint 2: a closer look

The missing expression is message, without quotes.

How the answer works

The result contains two signed whole numbers separated by a comma. The minus sign belongs to the second number. Anyone who knows hex can decode it; no key has been used.

This replaces the code in the editor. Save your version first if you want to keep it.

Make it yours

Try bytes.fromhex("41").decode("utf-8"). Then change 41 to 42.

hex_clue.pyPYTHON 3

Four spaces indent a block. Ctrl / ⌘ + Enter runs your code. Tab moves to the next control.

OUTPUTPython loads when you run
Your program's output will appear here.

Take a guess. Try a line. See what happens.

Expected output

40701567000,-73775392000

Code runs on your device. The first run downloads the Python engine (about 10 MB); later runs use the browser cache. Stop ends a run without losing your code.