Binary Search (picoCTF 9)

Challenge Author: Jeffery John

Difficulty: Easy

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!

Process / Notes

  1. I didn’t take notes on this one, but once you connected to your challenge instance, you needed to input your guesses and the program would respond whether the target value was lower or higher than your guess
  2. The trick ended up being to divide the number in half, and set your previous guess as the floor or ceiling of your guessing window depending on which way the target value was.
  3. For example, if you guessed 500, and the response was “Higher”, 500 became your floor and your next guess would be 750 (half-way between 500 and the overall ceiling 1000)
  4. If 750 was too high, it would then become the ceiling and 500 would be the floor. Dividing that range in half would result in 625 being your next guess
  5. This would repeat until you arrived at the target number.

5 minutes 0 seconds to complete

Hints

  1. Have you every played hot or cold? Binary search is a bit like that
  2. You have a very limited number of guesses. Try larger jumps between numbers!
  3. The program will randomly choose a new number each time you connect. You can always try again, but you should start your binary search over from the beginning - try around 500. Can you think of why?

Core Lessons

  1. Understand the principle of binary search