=

Binary Search writeup - Pico CTF ( General skills )

Description : Want to play a game? As you use more of the shell, you might be interested in how they work! Binary search is a classic algorithm used to quickly find an item in a sorted list. Can you find the flag? You'll have 1000 possibilities and only 10 guesses.

Cyber security often has a huge amount of data to look through - from logs, vulnerability reports, and forensics. Practicing the fundamentals manually might help you in the future when you have to write your own tools!

Solution -

Step 1: Start with the Midpoint - The program will generate a random number between 1 and 1000, and our task is to guess it. We’re given only 10 chances. In binary search, we begin by dividing the search range in half. So, the first guess should be 500 (the midpoint between 1 and 1000).

The program will then tell us whether the number we're guessing is lower or higher than the target number.

Step 2: Narrowing Down the Range - Based on the feedback, if the target number is lower than 500, we focus on the lower half of the range, i.e., between 1 and 499. Our next guess should be the midpoint of that new range—around 250. If the target number is higher than 500, we shift our focus to the upper half (501 to 1000) and guess 750 next.

Step 3: Repeat the Process - We continue this process, each time halving the remaining search range until we either find the correct number or run out of guesses. With binary search, we should be able to guess the correct number within the 10 guesses allowed, since each guess eliminates half the remaining possibilities.

Binary search pico ctf solution image

Flag is - picoCTF{g00d_gu355_ee8225d0}