$ cat writeup.md…
$ cat writeup.md…
hackthebox
Task: Find two prime numbers in a list and output their product. Solution: Implement primality check and multiply the two primes found.
The task provided a web interface with a code editor. The goal was to write a script that reads a list of numbers from stdin, identifies the two prime numbers in the list, and outputs their product.
This is a classic coding challenge. We are given a list of numbers, among which we need to find exactly two prime numbers and multiply them. The main difficulty lies in correctly implementing the primality check and handling the input data.
#!/usr/bin/env python3 import sys def is_prime(n): if n < 2: return False for i in range(2, int(n**0.5) + 1): if n % i == 0: return False return True def solve(): try: # Read all input data input_data = sys.stdin.read().split() numbers = [int(x) for x in input_data] primes = [] for num in numbers: if is_prime(num): primes.append(num) if len(primes) == 2: print(primes[0] * primes[1]) else: # If there are not exactly 2 primes, output something or nothing pass except Exception as e: pass if __name__ == "__main__": solve()
The script is submitted to the /run endpoint via a POST request (or through the editor interface on the website), after which the server executes it on test data and returns the flag.
Use this technique when:
$ cat /etc/motd
Liked this one?
Pro unlocks every writeup, every flag, and API access. $9/mo.
$ cat pricing.md$ grep --similar