I’ve got a project that was put on my head by my professor without any guidance on how to do it. As far as I’ve understood from what I’ve read online, the audio is encrypted in such a way that it distorts the audio in a way that affects its intelligibility but leaves it still recognizable and you can decrypt it back to its original form.
I’ve tried to do some stuff in python but I keep running into a wall where I don’t know what to do anymore, any pointers, tips, or a roadmap on what to do would be well appreciated!
While the code does give me a distorted audio file I do not think this is what is truly needed.
import numpy as np
from scipy.fft import fft, ifft
from scipy.signal import hilbert
from pydub import AudioSegment
encryption_key = 0xA5
audio = AudioSegment.from_wav('sound.wav')
samples = np.array(audio.get_array_of_samples())
frequency_data = fft(samples)
magnitude = np.abs(frequency_data)
phase = np.angle(frequency_data)
for i in range(len(frequency_data)):
if i > len(frequency_data) * 0.3:
encrypted_phase = phase[i] + encryption_key / 100.0
frequency_data[i] = magnitude[i] * np.exp(1j * encrypted_phase)
modified_samples = ifft(frequency_data).real
modified_audio = AudioSegment(
data=modified_samples.astype(np.int16).tobytes(),
sample_width=audio.sample_width,
frame_rate=audio.frame_rate,
channels=audio.channels
)
modified_audio.export("encrypted_audio.wav", format="wav")
Jayashankar N is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.