Skip to content

Commit

Permalink
Quartz sync: Sep 4, 2024, 1:24 PM
Browse files Browse the repository at this point in the history
  • Loading branch information
Tan-JunWei committed Sep 4, 2024
1 parent 0a3587d commit 92def74
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
43 changes: 43 additions & 0 deletions Binary Search.md
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/

Binary file added content/Assets/PicoCTF Binary Search 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/Assets/PicoCTF Binary Search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion content/PicoCTF/Forensics/WPA-ing Out.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Creation Date: 2024-08-28
Last Date: 2024-08-28
References:
draft:
modified: 2024-08-29T13:12:56+08:00
modified: 2024-09-04T13:23:53+08:00
---
## Challenge Description
![[PicoCTF WPA-ing Out.png]]
Expand Down
9 changes: 8 additions & 1 deletion content/PicoCTF/PicoCTF Writeups.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
modified: 2024-09-03T16:03:45+08:00
modified: 2024-09-04T12:57:17+08:00
---
<!-- ### Forensics
Expand Down Expand Up @@ -148,3 +148,10 @@ modified: 2024-09-03T16:03:45+08:00
- [[Flags]]
- [[john_pollard]]
- [[Tapping]]

### General Skills
- easy
- [[Binary Search]]
- [[Time Machine]]
- [[Super SSH]]
- medium
1 change: 1 addition & 0 deletions content/index.md
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]]
Expand Down

0 comments on commit 92def74

Please sign in to comment.