Lesson 5 of 6
The hidden record
- 20 min
- 5 checks
- 3 hints
- Go to task
Goal
Walk through records of varying length
Explanation
This is a block of bytes from a made-up data file. Its first byte is the number of records, and the records follow one after another. Each record starts with a tag byte that gives its type, then a length byte, then that many bytes of data:
count | tag len data... | tag len data... | ...
The record whose tag is 0xFF holds the flag. The records have different lengths, so you can't know where a record starts until you've read the length of the one before it.
Your task
Write a function extract_flag(blob) that reads the records in order and returns the data of the record whose tag is 0xFF as bytes, or None if the block has no such record. The checks give it other blocks with different records.
Checks
5 checks- Extracts the flag from the first record
- Finds the flag in the third record
- Handles empty and long records
- Isn't fooled by 0xFF bytes inside the data
- Returns None when there's no flag record