Forked from reachsumit/Audio Steganography - receiver.py
Created
July 16, 2019 18:56
-
-
Save Ma5onic/893daa38b3f05f68e4127b426be379a8 to your computer and use it in GitHub Desktop.
This code contains a demo for Audio Steganography. It is to be used by the receiver end, to extract the secret text embedded in the audio file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use wave package (native to Python) for reading the received audio file | |
import wave | |
song = wave.open("song_embedded.wav", mode='rb') | |
# Convert audio to byte array | |
frame_bytes = bytearray(list(song.readframes(song.getnframes()))) | |
# Extract the LSB of each byte | |
extracted = [frame_bytes[i] & 1 for i in range(len(frame_bytes))] | |
# Convert byte array back to string | |
string = "".join(chr(int("".join(map(str,extracted[i:i+8])),2)) for i in range(0,len(extracted),8)) | |
# Cut off at the filler characters | |
decoded = string.split("###")[0] | |
# Print the extracted text | |
print("Sucessfully decoded: "+decoded) | |
song.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment