Day 15 - Back to Hack The Box with "Primed for Action"
For Day 15, I returned to Hack The Box (HTB) to continue sharpening my skills. I decided to tackle another challenge from the cryptography category, this one called "Primed for Action." It seemed like a great opportunity to apply some fundamental number theory concepts in a practical scripting problem.
The Challenge: Primed for Action
The premise of the challenge is straightforward. I needed to connect to a service that would provide a long list of numbers. The description states:
"Intelligence units have intercepted a list of numbers. They seem to be used in a peculiar way - the adversary seems to be sending a list of numbers, most of which are garbage, but two of which are prime. These 2 prime numbers appear to form a key, which is obtained by multiplying the two."
So, the mission was clear: receive the list of numbers, identify the two prime numbers hidden within it, calculate their product, and submit the result to get the flag.
My Solution: Scripting with Python
This is a perfect task for a Python script. The logic involves two main parts: a function to check for primality and a main block to process the list of numbers.
1. The is_prime Function
First, I needed a reliable way to determine if a number is prime. I wrote a function using the trial division method. This is an efficient approach that checks for divisibility only up to the square root of the number, which is a key optimization.
def is_prime(x):
# Primes must be greater than 1
if x <= 1:
return False
# Check for factors from 2 up to the square root of x
for i in range(2, int(x**0.5) + 1):
if x % i == 0:
return False
return True
2. The Main Script
With the primality test ready, the rest of the script reads the input, filters the list to find the two primes, and calculates the product.
# Read the line of space-separated numbers
n = input()
numbers = list(map(int, n.strip().split()))
# (is_prime function from above)
# Use a list comprehension to filter for prime numbers
primes = [num for num in numbers if is_prime(num)]
# The problem guarantees there are exactly two primes
answer = primes[0] * primes[1]
# Print the final answer
print(answer)
Execution and Result
I connected to the service, provided the input to my script, and it quickly computed the product of the two primes. Submitting this product to the service solved the challenge and revealed the flag.
This challenge was a fun and practical application of basic number theory and a great exercise in scripting.
Flag: HTB{pr1m3_Pr0d_! }
Another successful day on Hack The Box! While this challenge was rated "Very Easy," it was a solid confidence booster and reinforced the importance of having a good set of helper functions ready for common tasks like primality testing. On to the next one!
#IDNBootCampCyber
Komentar
Posting Komentar