題目內容
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!
Hint:
1. Have you ever 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?
解題方法
這題我們要用 shell 玩猜數字的遊戲,從題敘和提供的 shell script (.sh檔)可以知道,數字範圍是 1 ~ 1000,而我們只有10次猜測的機會。相信有學過演算法的應該就知道標題的 Binary Search ,也就是二分搜尋法,其最基本的概念是,我們要在已經將資料排序過的串列中找出某筆特定資料,我們可以將串列從中間分成兩半,並拿中間的資料與我們要找的資料比較,如果比我們要的資料還小,代表我們要找的資料在比中間資料大的那半串列,反之則反,於是我們再將那半的串列分成兩半,重複操作,如此一來我們就能很快地找到我們要的資料。而我們可以利用這樣的概念在有限的次數內猜出數字。
因此我們按照指示用 shell 連進系統後,以上述的概念進行猜數字遊戲,便可以得到 flag。