-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a3587d
commit 92def74
Showing
6 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
--- | ||
tags: | ||
- GeneralSkills | ||
- BinarySearch | ||
- SSH | ||
- easy | ||
Creation Date: | ||
Last Date: | ||
References: | ||
draft: | ||
modified: 2024-09-04T13:23:50+08:00 | ||
--- | ||
## Challenge Description | ||
|
||
![[PicoCTF Binary Search.png]] | ||
As the name suggests, this challenge will be about binary search. | ||
|
||
>[!tip] What is binary search? | ||
> | ||
>From the [GeeksforGeeks Binary Search Algorithm](https://www.geeksforgeeks.org/binary-search/) page, the _Binary Search Algorithm_ is a [searching algorithm](https://www.geeksforgeeks.org/searching-algorithms/) used in a sorted array by repeatedly dividing the search interval in half**. The idea of binary search is to use the information that the array is sorted and reduce the time complexity to O(log N). | ||
For this challenge, we will have to guess a number between 1 and 1000. This number is randomly generated every time a user connects to the SSH server. We will only be given the flag is we guess the number. | ||
|
||
>[!faq] PicoCTF Hint: 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? | ||
> | ||
>Basically, in the binary search algorithm, there will be 2 important values - the upper and lower bound. For example, in this challenge, the initial upper bound is 1000, and of course the lower bound is 1. | ||
> | ||
>According the the binary search algorithm, we are basically adjusting either the upper or lower bound during each guess. Each guess will be the middle value between the upper and lower bound. Thus, after each guess, we will have reduced our search space by half. | ||
### Implementing the binary search algorithm | ||
![[PicoCTF Binary Search 2.png]] | ||
As mentioned earlier, the initial upper bound is 1000 and the lower bound is 1. We will start by guessing the middle value, which is 500. Since the output tells us that the target value is higher than 500, our new lower bound is now 501. The upper bound is still 1000. Search space is reduced to `501-1000`. | ||
|
||
Next, we guess the middle value of the new upper and lower bound (750). As observed, the target value is lower than 750, so we adjust the upper bound to 749 accordingly. Our search space is reduced to `501-749`. | ||
|
||
We continue implementing the binary search algorithm until we get the target value. In my attempt, the target value was `650`. After guessing this value correctly, the flag was displayed in the next line. | ||
|
||
> [!NOTE] Flag | ||
> picoCTF{g00d_gu355_1597707f} | ||
#### References | ||
- GeeksforGeeks. (2024c, August 29). _Binary Search Algorithm Iterative and Recursive Implementation_. GeeksforGeeks. https://www.geeksforgeeks.org/binary-search/ | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
--- | ||
title: CTF Writeups | ||
modified: 2024-09-04T12:56:10+08:00 | ||
--- | ||
|
||
![[banner.jpg]] | ||
|