Guest User

WannaGame CTF 2022: Zero-One Search

a guest
Oct 11th, 2022
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.22 KB | Source Code | 0 0
  1. from Crypto.Random.random import randint
  2. from secret import flag
  3.  
  4.  
  5. class Challenge:
  6.     def __init__(self):
  7.         self.rounds = 50
  8.  
  9.     def checking(self, list_num, magic_num):
  10.         for i in list_num:
  11.             if i == magic_num:
  12.                 return True
  13.         return False
  14.  
  15.     def quest(self):
  16.         turns = 10
  17.         magic_num = randint(0, 1023)
  18.         for i in range(turns):
  19.  
  20.             req = int(input(">>> "))
  21.             try:
  22.                 list_num = list(map(int, req.split()))
  23.             except:
  24.                 print("Nice try, kiddo!")
  25.                 return False
  26.             if self.checking(list_num, magic_num):
  27.                 print("YES")
  28.             else:
  29.                 print("NO")
  30.         try:
  31.             print("Your final answer is : ")
  32.             answer = int(input())
  33.             if answer == magic_num:
  34.                 print("Correct!")
  35.                 return True
  36.             else:
  37.                 print("Wrong!")
  38.                 return False
  39.         except:
  40.             print("Your answer is not valid!!!")
  41.             return False
  42.  
  43.     def main(self):
  44.         print("Welcome to my challenge!!!")
  45.         print("In this challenge, you have to past 50 rounds, each round have 1 magic numbers.")
  46.         print("Your task is to guess that number.")
  47.         print("You can ask me at most 10 questions.")
  48.         print("Let\'s assume you want to know if magic number is in (1, 2, 3, 4, 5) list, then you have to send like \"1 2 3 4 5\", each seperate by a space.")
  49.         print("After that, you will receive two kind of answers.")
  50.         print("YES if the magic number is in the list you send me.")
  51.         print("NO if the magic number is not in the list you send me.")
  52.         print("After 10 turns, you will give me the final asnwer, if it is correct, you pass, if wrong, you lose.")
  53.         print("Good luck, hackers!!!")
  54.         for i in range(self.rounds):
  55.             print(("Challenge " + str(i) + " :"))
  56.             if self.quest():
  57.                 print(("You passed the challenge " + str(i) + "th"))
  58.             else:
  59.                 print("You failed!")
  60.                 return
  61.         print("Here is your flag : " + flag)
  62.  
  63.  
  64. Chall = Challenge()
  65. Chall.main()
Advertisement
Add Comment
Please, Sign In to add comment