From a69dc5437ea53c19c3eb3040a539b20ee3e64473 Mon Sep 17 00:00:00 2001 From: Maxime Vorwerk Date: Sun, 16 Jun 2024 20:31:30 +0200 Subject: [PATCH] binary search --- binary_search/challenge.zip | Bin 0 -> 1041 bytes .../home/ctf-player/drop-in/guessing_game.sh | 47 ++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 binary_search/challenge.zip create mode 100755 binary_search/home/ctf-player/drop-in/guessing_game.sh diff --git a/binary_search/challenge.zip b/binary_search/challenge.zip new file mode 100755 index 0000000000000000000000000000000000000000..18679b6c8f56e89deccf0cdd630a23839ceba81d GIT binary patch literal 1041 zcmWIWW@h1H0D&~doCq)jN=PusFl6NCrs^k`r0EvqBvz&t>8BLs7wBf@>4%1JGBD4d z`#u$fODnh;7+GF0GcbUO0HBE?Kr=YNCJN^6)30V?V9;h`V9>y0VtQ$6adBo|dVG3f zZmM2!1{NDY?qUHEQ$yb8Up5f3Ni&?s-{ zDc`88AJqF=w07^g@IvyPyvv*g?}GN{HXQXiA$Dv=UV8m!`J4VLf6nvGn`LB^R(Z$=b5wg~PfnZh6{!`4@(7`aDZ$=T`RV8Cw@bY8^N|<>-bhTH5=J zw&)~Ho5-DMtuF3g&YmvjX0!02ljP$U{CO4WQ(ER1d}rn}`Qa@7_WOTTyR0w1H<#$m zxUt*4`uvWQ?FXhlNRzpCNG+l0++6h-*R^}M{FT(~+}&Ig*q48ZXX*0}!OmG5*(W}Y zd~Gs)i}R$K&zCNK^E|%)fYTwan7btj6ieWHU{A_9WyJT d*amVKI2#3cvjQ_E0|OHfo&nPOz#PoL002a#kUIbX literal 0 HcmV?d00001 diff --git a/binary_search/home/ctf-player/drop-in/guessing_game.sh b/binary_search/home/ctf-player/drop-in/guessing_game.sh new file mode 100755 index 0000000..b98f32b --- /dev/null +++ b/binary_search/home/ctf-player/drop-in/guessing_game.sh @@ -0,0 +1,47 @@ + + #!/bin/bash + + # Generate a random number between 1 and 1000 + target=$(( (RANDOM % 1000) + 1 )) + + echo "Welcome to the Binary Search Game!" + echo "I'm thinking of a number between 1 and 1000." + + # Trap signals to prevent exiting + trap 'echo "Exiting is not allowed."' INT + trap '' SIGQUIT + trap '' SIGTSTP + + # Limit the player to 10 guesses + MAX_GUESSES=10 + guess_count=0 + + while (( guess_count < MAX_GUESSES )); do + read -p "Enter your guess: " guess + + if ! [[ "$guess" =~ ^[0-9]+$ ]]; then + echo "Please enter a valid number." + continue + fi + + (( guess_count++ )) + + if (( guess < target )); then + echo "Higher! Try again." + elif (( guess > target )); then + echo "Lower! Try again." + else + echo "Congratulations! You guessed the correct number: $target" + + # Retrieve the flag from the metadata file + flag=$(cat /challenge/metadata.json | jq -r '.flag') + echo "Here's your flag: $flag" + exit 0 # Exit with success code + fi + done + + # Player has exceeded maximum guesses + echo "Sorry, you've exceeded the maximum number of guesses." + exit 1 # Exit with error code to close the connection + + \ No newline at end of file