You are on page 1of 2

# -*- coding: utf-8 -*-

"""
Created on Sat Feb 15 18:17:54 2020

@author: amna
"""

import numpy as np
from random import seed

import wave

#lists define
pix=[]
stegoPix=[]
data=[]
Wave_write=[]
twoD=[]

audio =wave.open('sampleAudio.wav',mode='rb')
oneD = bytearray(list(audio.readframes(audio.getnframes())))
st = input("please enter data you want to hide: ", )
DataBitStream=''.join(format(ord(x), 'b').zfill(7) for x in st)

BitStream_arr = list(DataBitStream)
#length of data
c=len(DataBitStream)
x=input("enter the seed: ")
np.random.seed(int(x))

#random non-repeating secret key


SecretKey=np.random.permutation(c)
for x in range(0,c):
pix.append((int(oneD[SecretKey[x]])))
#hiding data
for x in range(0,c):
if (int(BitStream_arr[x]) == 1): #if data we want to hide is 1
if (pix[x] % 2 == 0):
pix[x]=pix[x]+1 #if pixel is even then made it odd

if(int(BitStream_arr[x]) == 0): #if data we want to hide is 0


if (pix[x] % 2 != 0):
pix[x]= pix[x]-1
#i
for x in range(0,c):
oneD[SecretKey[x]]=pix[x]

frame_mod = bytes(oneD)
with wave.open('song_embedded.wav', 'wb') as fd:
fd.setparams(audio.getparams())
fd.writeframes(frame_mod)
audio.close()
song= wave.open("song_embedded.wav", mode='rb')
# Convert audio to byte array
oneDstego = bytearray(list(song.readframes(song.getnframes())))

for x in range(0,c):
stegoPix.append((int(oneDstego[SecretKey[x]])))

#finding data hidden


for x in range(0,c):

#if picked pixel is even then hidden data is '0'


if(int(stegoPix[x]) % 2 == 0):
data.append(0)
#if picked pixel is odd then hidden data is '1'
if(int(stegoPix[x]) % 2 != 0):
data.append(1)
#from list to string
datastr= "".join(map(str, data))

message = ""
#from bitstream into string of character
while datastr != "":
i =chr( int(datastr[:7], 2))
message = message + i
datastr = datastr[7:]
print ("the hidden message is: ",message)

You might also like