#!/usr/bin/env python3 from Crypto.Util.number import getStrongPrime import random, sys, os import signal FLAG = "PPC2023{debug_flag}" BANNER = ''' _____ _____ _| |_______________________| |_ | $ | | $ | | ||| | $$ Secure House! $$ | ||| | | | | | | [ ] | [ ] [ ] [ ] | [ ] | | |---------------------| | | [ ] | _ _ .---. _ _ | [ ] | | | | | | |_|_| | | | | | |_____|_|_|_|__|_|_|__|_|_|_|_____| //=======\\ ''' class RNG: def __init__(self, seed): self.p = getStrongPrime(512) self.a = random.getrandbits(512) self.state = int.from_bytes(seed, "big") def _next(self): self.state = (self.state**2 + self.a) % self.p return self.state >> 170 class Game(): def __init__(self): self.seed = os.urandom(64) self.rng = RNG(self.seed) self.wallet = 10 def _start(self): print(BANNER) print(f"Welcome to our secure house! Let's start.\nGuess the code, but each guess will cost you 4 times the entered code ..! Enter or Pay") print(f"Here are the public parameters:\np = {hex(self.rng.p)}\na = {hex(self.rng.a)}") while True: print(f"Your current wallet is {self.wallet}$.\n") if self.wallet > int.from_bytes(b"Purple_Pill", "big"): print(f"Welcome! You have access to secret house: {FLAG}") sys.exit() code = int(input("Place your code: ")) if (code > self.wallet) or (code <= 0): print("Invalid code! Please check your wallet.") sys.exit() server_num = self.rng._next() guest_num = int(input("Place your code: ")) if server_num == guest_num: self.wallet += code print(f"You got it right, the code was: {hex(server_num)}\n") else: self.wallet -= 4*code print(f"incorrect, the code was: {hex(server_num)}\n") if self.wallet <= 0: print("Sorry, you have no money left in your wallet and you don't have access,Goodbye!") sys.exit() signal.alarm(60) if __name__ == "__main__": Game()._start()