User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Legacy and Other Languages section within the Software Development category of DaniWeb, a massive community of 422,420 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 5,280 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Legacy and Other Languages advertiser: Programming Forums
Views: 493 | Replies: 0
Reply
Join Date: May 2008
Posts: 1
Reputation: abdullilah is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
abdullilah abdullilah is offline Offline
Newbie Poster

i want to convert this code with c++ to matlab code

  #1  
May 23rd, 2008
which hide text and audio
please help me
code :
-------------------------------------------------------------------------------
public void Hide(Stream messageStream, Stream keyStream){

byte[] waveBuffer = new byte;
byte message, bit, waveByte;
int messageBuffer; //receives the next byte of the message or -1
int keyByte; //distance of the next carrier sample

//loop over the message, hide each byte
while( (messageBuffer=messageStream.ReadByte()) >= 0 ){
//read one byte of the message stream
message = (byte)messageBuffer;

//for each bit in [message]
for(int bitIndex=0; bitIndex<8; bitIndex++){

//read a byte from the key
keyByte = GetKeyValue(keyStream);

//skip a couple of samples
for(int n=0; n<keyByte-1; n++){
//copy one sample from the clean stream to the carrier stream
sourceStream.Copy(
waveBuffer, 0,
waveBuffer.Length, destinationStream);
}

//read one sample from the wave stream
sourceStream.Read(waveBuffer, 0, waveBuffer.Length);
waveByte = waveBuffer;

//get the next bit from the current message byte...
bit = (byte)(((message & (byte)(1 << bitIndex)) > 0) ? 1 : 0);

//...place it in the last bit of the sample
if((bit == 1) && ((waveByte % 2) == 0)){
waveByte += 1;
}else if((bit == 0) && ((waveByte % 2) == 1)){
waveByte -= 1;
}

waveBuffer = waveByte;

//write the result to destinationStream
destinationStream.Write(waveBuffer, 0, bytesPerSample);
}
}

//copy the rest of the wave without changes
//...
}
--------------------------------------
Extracting the Message
public void Extract(Stream messageStream, Stream keyStream){

byte[] waveBuffer = new byte;
byte message, bit, waveByte;
int messageLength = 0; //expected length of the message
int keyByte; //distance of the next carrier sample

while( (messageLength==0 || messageStream.Length<messageLength) ){
//clear the message-byte
message = 0;

//for each bit in [message]
for(int bitIndex=0; bitIndex<8; bitIndex++){

//read a byte from the key
keyByte = GetKeyValue(keyStream);

//skip a couple of samples
for(int n=0; n<keyByte; n++){
//read one sample from the wave stream
sourceStream.Read(waveBuffer, 0, waveBuffer.Length);
}
waveByte = waveBuffer;

//get the last bit of the sample...
bit = (byte)(((waveByte % 2) == 0) ? 0 : 1);

//...write it into the message-byte
message += (byte)(bit << bitIndex);
}

//add the re-constructed byte to the message
messageStream.WriteByte(message);

if(messageLength==0 && messageStream.Length==4){
//first 4 bytes contain the message's length
//...
}
}
}
-------------------
Last edited by abdullilah : May 23rd, 2008 at 2:18 pm.
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Legacy and Other Languages Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Legacy and Other Languages Forum

All times are GMT -4. The time now is 9:41 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC