Click here to Skip to main content
15,891,033 members
Home / Discussions / C#
   

C#

 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Toni Andika11-Mar-16 1:24
Toni Andika11-Mar-16 1:24 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Sascha Lefèvre11-Mar-16 1:31
professionalSascha Lefèvre11-Mar-16 1:31 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Toni Andika11-Mar-16 2:06
Toni Andika11-Mar-16 2:06 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Sascha Lefèvre11-Mar-16 2:43
professionalSascha Lefèvre11-Mar-16 2:43 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Toni Andika14-Mar-16 1:17
Toni Andika14-Mar-16 1:17 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Sascha Lefèvre14-Mar-16 1:49
professionalSascha Lefèvre14-Mar-16 1:49 
AnswerRe: steganography cover audio using modification LSB and phase coding technique Pin
OriginalGriff10-Mar-16 23:44
mveOriginalGriff10-Mar-16 23:44 
GeneralRe: steganography cover audio using modification LSB and phase coding technique Pin
Toni Andika11-Mar-16 1:53
Toni Andika11-Mar-16 1:53 
no no I'm sorry about that, I don't mean like that. I was try to build application about steganography. It was use AES encryption and LSB technique and I had a problem on the extention of audio. The Cover audio is wav and midi but when I was insert chipertext into audio(midi) there is a problem with the code and so much the noise (the SNR is so weak)
this is my code: AES Encryption steganography cover audio using LSB technique


using System;

using System.Drawing;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.IO;

using System.Text;

using System.Windows.Forms;

using System.Threading;



namespace StegAudio

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}



private void buttonnamafile_Click(object sender, EventArgs e)

{

OpenFileDialog dlg = new OpenFileDialog();

GetFileName(dlg, textBoxHideFile, false);

}



private void buttontempatfile_Click(object sender, EventArgs e)

{

SaveFileDialog dlg = new SaveFileDialog();

GetFileName(dlg, textBoxDestFile, true);

}



private void GetFileName(FileDialog dialog, TextBox control, bool useFilter)

{

if (useFilter) { dialog.Filter = "Wave Audio (*.wav)|*.wav|MIDI (*.mid)|*.mid";}

if (dialog.ShowDialog(this) == DialogResult.OK)

{

control.Text = dialog.FileName;

}

}



private string GetFileExtension(string filename)

{

return filename.Substring(filename.Length - 3, 3);

}



private void buttoncariaudio_Click(object sender, EventArgs e)

{

OpenFileDialog dlg = new OpenFileDialog();

GetFileName(dlg, textBoxHideAudio, true);

}



private void buttonfileakhir_Click(object sender, EventArgs e)

{

SaveFileDialog dlg = new SaveFileDialog();

GetFileName(dlg, textBoxExtDest, false);

}



private void buttonsembunyi_Click(object sender, EventArgs e)

{

if(textBoxHideAudio.Text.Length == 0)

{

errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file.");

}

else if(textBoxPWH.Text.Length == 0)

{

errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");

}

else if(textBoxDestFile.Text.Length == 0)

{

errorProvider1.SetError(textBoxDestFile, "The resulting carrier file must be saved somewhere.");

}

else if (textBoxHideFile.Text.Length == 0)

{

errorProvider1.SetError(textBoxHideFile, "What am I supposed to hide?");

}

else

{

//before we hide the message into the wav file, we must encrypt it first

//in this case, we are using Rijndael encryption

MyEncryptor encryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase

String encryptedMessage = encryptor.Encrypt(GetMessageString());



//reset all the stream first

Stream sourceStream = null;

FileStream destinationStream = null;

WaveStream audioStream = null;



Stream messageStream = GetMessageStream(encryptedMessage); //write the encrypted message into the stream



Stream keyStream = GetKeyStream();



string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message

fileExtension = GetFileExtension(textBoxHideAudio.Text);

if (fileExtension.Equals("wav"))

{

try

{

//how many samples do we need

long countSampleRequired = WaveUtility.CheckKeyForMessage(keyStream, messageStream.Length);



if (countSampleRequired > Int32.MaxValue)

{

throw new Exception("Message too long, or bad key! This message/key combination requires " + countSampleRequired + " samples, only " + Int32.MaxValue + " samples are allowed.");

}



//use wav file as the carrier

sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);



this.Cursor = Cursors.WaitCursor;



//create empty file for the carrier wave

destinationStream = new FileStream(textBoxDestFile.Text, FileMode.Create);



//copy the carrier file's header

audioStream = new WaveStream(sourceStream, destinationStream);

if (audioStream.Length <= 0)

{

throw new Exception("Invalid WAV file");

}



//are there enough samples in the carrier wave?

if (countSampleRequired > audioStream.CountSamples)

{

String errorReport = "The carrier file is too small for this message and key!\r\n"

+ "Samples available: " + audioStream.CountSamples + "\r\n"

+ "Samples needed: " + countSampleRequired;

throw new Exception(errorReport);

}



//hide message

WaveUtility utility = new WaveUtility(audioStream, destinationStream);

utility.Hide(messageStream, keyStream);

}

catch (Exception ex)

{

this.Cursor = Cursors.Default;

MessageBox.Show(ex.Message);

}

finally

{

if (keyStream != null) { keyStream.Close(); }

if (messageStream != null) { messageStream.Close(); }

if (audioStream != null) { audioStream.Close(); }

if (sourceStream != null) { sourceStream.Close(); }

if (destinationStream != null) { destinationStream.Close(); }

this.Cursor = Cursors.Default;

MessageBox.Show("file has success Inserted");

}

}

else if (fileExtension.Equals("mid"))

{

//i'll make it simple, coz the method is slightly different in code than wav. Another reason is that i'm lazy enough not to port the code.

try

{

this.Cursor = Cursors.WaitCursor;



MidiUtility utility = new MidiUtility();

utility.HideMessage(textBoxHideAudio.Text, textBoxDestFile.Text, messageStream, keyStream);

}

catch (Exception ex)

{

this.Cursor = Cursors.Default;

MessageBox.Show(ex.Message);

}

finally

{

if (keyStream != null) { keyStream.Close(); }

if (messageStream != null) { messageStream.Close(); }

if (audioStream != null) { audioStream.Close(); } //actually, these two streams aren't needed in this method

if (sourceStream != null) { sourceStream.Close(); } //but let's write them anyway...Smile | :)

if (destinationStream != null) { destinationStream.Close(); }

}

}

}

}



private Stream GetMessageStream()

{

BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());



//open the file to be hidden

FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);

int filelength = (int)fs.Length;

messageWriter.Write(filelength); //save the length of file into binary stream

byte[] buffer = new byte[fs.Length]; //allocate the buffer as big as the file length

fs.Read(buffer, 0, filelength); //read the file into the buffer

messageWriter.Write(buffer); //save the buffer into binary stream

fs.Close(); //close the file when operation finished



messageWriter.Seek(0, SeekOrigin.Begin);

return messageWriter.BaseStream;

}



private Stream GetMessageStream(string message)

{

BinaryWriter messageWriter = new BinaryWriter(new MemoryStream());



messageWriter.Write(message.Length);

messageWriter.Write(Encoding.ASCII.GetBytes(message));



messageWriter.Seek(0, SeekOrigin.Begin);

return messageWriter.BaseStream;

}



private String GetMessageString()

{

FileStream fs = new FileStream(textBoxHideFile.Text, FileMode.Open);

StreamReader rd = new StreamReader(fs);



return rd.ReadToEnd();

}



private Stream GetKeyStream()

{

BinaryWriter keyWriter = new BinaryWriter(new MemoryStream());



//write the password to the binary stream

keyWriter.Write(Encoding.ASCII.GetBytes(textBoxPWH.Text));



keyWriter.Seek(0, SeekOrigin.Begin);

return keyWriter.BaseStream;

}



private void buttonekstract_Click(object sender, EventArgs e)

{

if (textBoxHideAudio.Text.Length == 0)

{

errorProvider1.SetError(textBoxHideAudio, "You forgot to choose a carrier file.");

}

else if (textBoxPWH.Text.Length == 0)

{

errorProvider1.SetError(textBoxPWH, "You forgot to write a key.");

}

else

{

this.Cursor = Cursors.WaitCursor;

FileStream sourceStream = null;

WaveStream audioStream = null;

//create an empty stream to receive the extracted message

MemoryStream messageStream = new MemoryStream();



Stream keyStream = GetKeyStream();



string fileExtension; //fileextension indicating the format of audio file as the carrier of the secret message

fileExtension = GetFileExtension(textBoxHideAudio.Text);

if (fileExtension.Equals("wav"))

{

try

{

//open the carrier file

sourceStream = new FileStream(textBoxHideAudio.Text, FileMode.Open);

audioStream = new WaveStream(sourceStream);

WaveUtility utility = new WaveUtility(audioStream);



//extract the message from the carrier wave

utility.Extract(messageStream, keyStream);



messageStream.Seek(0, SeekOrigin.Begin);



//save result to a file

FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);



//before the result message is saved in the destination file, decrypt it first

MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase

StreamReader rd = new StreamReader(messageStream);

String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());

StreamWriter wr = new StreamWriter(fs);



wr.Write(decryptedMessage);



wr.Flush();

fs.Close();

}

catch (Exception ex)

{

this.Cursor = Cursors.Default;

MessageBox.Show(ex.Message);

}

finally

{

if (keyStream != null) { keyStream.Close(); }

if (messageStream != null) { messageStream.Close(); }

if (audioStream != null) { audioStream.Close(); }

if (sourceStream != null) { sourceStream.Close(); }

this.Cursor = Cursors.Default;

MessageBox.Show("Ekstraksi Pesan Telah Selesai");

}

}

else if (fileExtension.Equals("mid"))

{

try

{

MidiUtility utility = new MidiUtility();

utility.ExtractMessage(textBoxHideAudio.Text, null, messageStream, keyStream);



messageStream.Seek(0, SeekOrigin.Begin);



//save result to a file

FileStream fs = new FileStream(textBoxExtDest.Text, FileMode.Create);



//before the result message is saved in the destination file, decrypt it first

MyEncryptor decryptor = new MyEncryptor(textBoxPWH.Text); //we use the key password as a secret phase

StreamReader rd = new StreamReader(messageStream);

String decryptedMessage = decryptor.Decrypt(rd.ReadToEnd());

StreamWriter wr = new StreamWriter(fs);



wr.Write(decryptedMessage);



wr.Flush();

fs.Close();

}

catch (Exception ex)

{

this.Cursor = Cursors.Default;

MessageBox.Show(ex.Message);

}

finally

{

if (keyStream != null) { keyStream.Close(); }

if (messageStream != null) { messageStream.Close(); }

if (audioStream != null) { audioStream.Close(); }

if (sourceStream != null) { sourceStream.Close(); }

this.Cursor = Cursors.Default;

MessageBox.Show("Extraction Messages Completed");

}

}

}

}

}

}
QuestionIs this possible? trying to split a string out of a value and then back into a IEnumerable....... Pin
Helixpoint10-Mar-16 5:16
Helixpoint10-Mar-16 5:16 
AnswerRe: Is this possible? trying to split a string out of a value and then back into a IEnumerable....... Pin
PIEBALDconsult10-Mar-16 5:29
mvePIEBALDconsult10-Mar-16 5:29 
Question[SOLVED]I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 3:05
professionalglennPattonWork310-Mar-16 3:05 
AnswerRe: I am having an issue with Boolean variables... Pin
OriginalGriff10-Mar-16 3:18
mveOriginalGriff10-Mar-16 3:18 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 3:30
professionalglennPattonWork310-Mar-16 3:30 
GeneralRe: I am having an issue with Boolean variables... Pin
OriginalGriff10-Mar-16 3:35
mveOriginalGriff10-Mar-16 3:35 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 4:40
professionalglennPattonWork310-Mar-16 4:40 
GeneralRe: I am having an issue with Boolean variables... Pin
OriginalGriff10-Mar-16 5:08
mveOriginalGriff10-Mar-16 5:08 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 5:15
professionalglennPattonWork310-Mar-16 5:15 
GeneralRe: I am having an issue with Boolean variables... Pin
OriginalGriff10-Mar-16 5:30
mveOriginalGriff10-Mar-16 5:30 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 5:39
professionalglennPattonWork310-Mar-16 5:39 
GeneralRe: I am having an issue with Boolean variables... Pin
Luc Pattyn10-Mar-16 8:58
sitebuilderLuc Pattyn10-Mar-16 8:58 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 13:48
professionalglennPattonWork310-Mar-16 13:48 
GeneralRe: I am having an issue with Boolean variables... Pin
PIEBALDconsult10-Mar-16 4:19
mvePIEBALDconsult10-Mar-16 4:19 
GeneralRe: I am having an issue with Boolean variables... Pin
glennPattonWork310-Mar-16 4:28
professionalglennPattonWork310-Mar-16 4:28 
QuestionShowing a ProgressBar from a FileSystemWatcher Pin
Paböö .10-Mar-16 1:53
Paböö .10-Mar-16 1:53 
AnswerRe: Showing a ProgressBar from a FileSystemWatcher Pin
Richard MacCutchan10-Mar-16 2:39
mveRichard MacCutchan10-Mar-16 2:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.