Deep in the alien cave system, you find a strange device. It seems to be some sort of communication cipherer, but only a couple of recordings are still intact. Can you figure out what the aliens were trying to say? The flag is all lower case
Downloads
Solution
For this challenge, we're given a really short python script and 2 '.wav' sound files.
import numpy as np
import soundfile as sf
flag, rate = sf.read('../htb/flag.wav')
# randomly shuffle the frequencies
freqs = np.fft.rfftfreq(len(flag), 1.0/rate)
filter_frequency_response = np.random.uniform(-10, 10, len(freqs))
# get the amplitudes
def filter(sample):
amplitudes = np.fft.rfft(sample)
shuffled_amplitudes = amplitudes * filter_frequency_response
return np.fft.irfft(shuffled_amplitudes)
impulse = np.zeros(len(flag))
impulse[0] = 1
shuffled_signal = filter(impulse)
sf.write('impulse_response.wav', shuffled_signal, rate)
shuffled_flag = filter(flag)
sf.write('shuffled_flag.wav', shuffled_flag, rate)
What this code does is that it first generates a random sound wave and multiplies it with a very simple impulse wave that is generated with the following code:
The result is then multiplied with the amplitude of the flag.wav sound file.
We can add print statements to see the before and after of the multiplication of the impulse.
Since the impulse simply adds a complex component, we can use the real keyword to get back the generated random noise.
After getting back the randomized noise, we simply need to use the shuffled flag sound waves and divide the amplitudes with the random noise. The solve script is as follows:
import numpy as np
import soundfile as sf
impulse, rate = sf.read('impulse_response.wav')
shuffled_flag, rate = sf.read('shuffled_flag.wav')
# Get the randomized filter_frequency_response
impulse_response = np.fft.rfft(impulse).real
print(impulse_response)
# Get the amplitudes of the shuffled flag
flag_amplitudes = np.fft.rfft(shuffled_flag)
print(flag_amplitudes)
# Divide the amplitudes with the random noise
amplitudes = flag_amplitudes / impulse_response
print(amplitudes)
# Inverse fourier transform
flag = np.fft.irfft(amplitudes)
sf.write('flag.wav', flag, rate)