• Tidak ada hasil yang ditemukan

Perbandingan Algoritma Steganografi echo Data Hiding Dan Low Bit Encoding Dalam Pengamanan File

N/A
N/A
Protected

Academic year: 2017

Membagikan "Perbandingan Algoritma Steganografi echo Data Hiding Dan Low Bit Encoding Dalam Pengamanan File"

Copied!
10
0
0

Teks penuh

(1)

LAMPIRAN A : LISTING PROGRAM

1. Form Utama

using System;

using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data;

using System.IO; using System.Text; using System.Threading;

namespace StegoAudio

{ public formStego(){InitializeComponent();}

protected override void Dispose( bool disposing ) {

if( disposing ) {if (components != null) {components.Dispose();}} base.Dispose( disposing ); }

private void OpenFileDialog(FileDialog dialog, TextBox control, bool useFilter) {if (useFilter) {dialog.Filter = "Wave Audio (*.wav)|*.wav";}

if (dialog.ShowDialog(this) == DialogResult.OK) { control.Text = dialog.FileName; }}

private void OpenFileDialog2(OpenFileDialog dlg, TextBox txtKeyFile, bool useFilter)

{if (useFilter)

{dlg.Filter = "File (*.txt)|*.txt";}

if (dlg.ShowDialog(this) == DialogResult.OK) {txtKeyFile.Text = dlg.FileName; }}

private void OpenFileDialog3(OpenFileDialog dlg, TextBox txtMsgFile, bool useFilter)

{if (useFilter)

{dlg.Filter = "File (*.txt)|*.txt";}

if (dlg.ShowDialog(this) == DialogResult.OK) {txtMsgFile.Text = dlg.FileName; }}

(2)

{dialog.Filter = "Wave Audio (*.wav)|*.wav";} if (dialog.ShowDialog(this) == DialogResult.OK)

{control.Text = dialog.FileName; }}

private void Audio_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog();

OpenFileDialog(dlg, txtAudio, true); }

private void StegoAudio_Click(object sender, System.EventArgs e){ SaveFileDialog dlg = new SaveFileDialog();

OpenFileDialog(dlg, txtStegoAudio, true); }

private void KeyFile_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog();

OpenFileDialog2(dlg, txtStegoKey, true); }

private void HideFile_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog();

OpenFileDialog3(dlg, txtHideFile, true); rdoHideFile.Checked = true;}

private void SaveFIle_Click(object sender, System.EventArgs e) { SaveFileDialog dlg = new SaveFileDialog();

OpenFileDialog(dlg, txtHiddenFile, false); rdoHiddenFile.Checked = true;}

private void HideLBE_Click(object sender, System.EventArgs e) { if (rdoAudio.Checked && (txtAudio.Text.Length == 0)){ errorProvider.SetError(txtAudio, "Choose an Audio.");} else if (txtStegoKey.Text.Length == 0){

errorProvider.SetError(txtStegoKey, "Choose a stego key file."); else if (rdoHideFile.Checked && (txtHideFile.Text.Length == 0)){

errorProvider.SetError(txtHideFile, "msg to hide."); }

else if (rdoHidemsg.Checked && (txtHidemsg.Text.Length == 0)) { errorProvider.SetError(txtHidemsg, "msg to hide."); }

else if (txtStegoAudio.Text.Length == 0) {

errorProvider.SetError(txtStegoAudio, "Save Stego Audio with new name."); }

else{

var watch = System.Diagnostics.Stopwatch.StartNew(); Stream carrierStream = null;

(3)

Stream msgStream = GetmsgStream();

Stream StegoKeyStream = new FileStream(txtStegoKey.Text, FileMode. Open);

try{

long samplesRequired = LBE.CheckKeyForMsg(StegoKeyStream,msgStream. Length);

if (samplesRequired > Int32.MaxValue) {

throw new Exception("Requires " + samplesRequired + " samples, only " +Int32.MaxValue + " samples are allowed."); }

if (rdoAudio.Checked) {

carrierStream = new FileStream(txtAudio.Text, FileMode.Open); } else{ formRecorder recorder = new formRecorder(samplesRequired);

recorder.ShowDialog(this);

carrierStream = recorder.RecordedStream; } this.Cursor = Cursors.WaitCursor;

stegoStream = new FileStream(txtStegoAudio.Text, FileMode.Create); audioStream = new WaveStream(carrierStream, stegoStream);

if (audioStream.Length <= 0) {

throw new Exception("Invalid WAV file");} if (samplesRequired > audioStream.CountSamples) {

MessageBox.Show("File carrier too small\r\n" + "Samples available: " + audioStream.CountSamples + "\r\n" + "Samples needed: " +

samplesRequired + "\r\n" + "\r\n" + "Click OK to record a new sound...." + "\r\n");

formRecorder recorder = new formRecorder(samplesRequired); recorder.ShowDialog(this);

carrierStream = recorder.RecordedStream; }

this.Cursor = Cursors.WaitCursor;

LBE combine = new LBE(audioStream, stegoStream); combine.Hide(msgStream, StegoKeyStream);

watch.Stop();

var elapsedMs = watch.ElapsedMilliseconds;

txtTime.Text = Convert.ToString(elapsedMs +" ms"); MessageBox.Show("Hiding Success");}

catch(Exception ex) {

(4)

MessageBox.Show(ex.Message);}

finally {

if(StegoKeyStream != null){ StegoKeyStream.Close(); } if(msgStream != null){ msgStream.Close(); } if(audioStream != null){ audioStream.Close(); } if(carrierStream != null){ carrierStream.Close(); } if(stegoStream != null){ stegoStream.Close(); }

this.Cursor = Cursors.Default;} }}

private void ExtractLBE_Click(object sender, EventArgs e) { if (txtAudio.Text.Length == 0)

{errorProvider.SetError(txtAudio, "Choose Stego Audio.");} else if (txtStegoKey.Text.Length == 0)

{errorProvider.SetError(txtStegoKey, "Choose a stego key file."); } else

{ var watch = System.Diagnostics.Stopwatch.StartNew(); Stream carrierStream = null;

FileStream stegoStream = null; WaveStream audioStream = null; Stream msgStream = GetmsgStream();

Stream StegoKeyStream = new FileStream(txtStegoKey.Text, FileMode.Open);

try

{long samplesRequired = LBE.CheckKeyFormsg(StegoKeyStream, msgStream.Length);

if (samplesRequired > Int32.MaxValue) {

throw new Exception("Requires " + samplesRequired + " samples, only " + Int32.MaxValue + " samples available.");}

if (rdoAudio.Checked)

{carrierStream = new FileStream(txtAudio.Text, FileMode.Open); } else{

formRecorder recorder = new formRecorder(samplesRequired); recorder.ShowDialog(this);

(5)

this.Cursor = Cursors.WaitCursor;

stegoStream = new FileStream(txtStegoAudio.Text, FileMode.Create);

audioStream = new WaveStream(carrierStream, stegoStream); if (audioStream.Length <= 0)

{throw new Exception("Invalid WAV file");} if (samplesRequired > audioStream.CountSamples) {MessageBox.Show("File carrier too small\r\n"

+ "Samples available: " + audioStream.CountSamples + "\r\n" + "Samples needed: " + samplesRequired + "\r\n" + "\r\n" + "Click OK to record a new sound...." + "\r\n");

formRecorder recorder = new formRecorder(samplesRequired); recorder.ShowDialog(this);

carrierStream = recorder.RecordedStream; } this.Cursor = Cursors.WaitCursor;

LBE combine = new LBE (audioStream, stegoStream); combine.embed(msgStream, StegoKeyStream);

watch.Stop();

var elapsedMs = watch.ElapsedMilliseconds;

txtTime.Text = Convert.ToString(elapsedMs + " ms"); MessageBox.Show("Hiding Success");}

catch (Exception ex) {

this.Cursor = Cursors.Default; Console.WriteLine(ex);

MessageBox.Show(ex.Message); }

2. Sisip

//LBE

finally{

if (StegoKeyStream != null) { StegoKeyStream.Close(); } if (msgStream != null) {

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

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

carrierStream.Close(); } if (stegoStream != null) {

stegoStream.Close(); }

this.Cursor = Cursors.Default; }}}

(6)

byte msg, bit, audioByte; int msgBuffer;

int keyByte;

while ((msgBuffer = msgStream.ReadByte()) >= 0) { msg = (byte)msgBuffer;

for (int msgIndex = 0; msgIndex < 8; msgIndex++) {keyByte = GetKeyValue(StegoKeyStream);

for (int n = 0; n < keyByte - 1; n++){

carrierStream.Copy(audioBuffer, 0, audioBuffer.Length, stegoStream); } carrierStream.Read(audioBuffer, 0, audioBuffer.Length);

audioByte = audioBuffer[bytesPerSample - 1];

bit = (byte)(((msg & (byte)(1 << msgIndex)) > 0) ? 1 : 0);

for (int pattern = 4; pattern >= 1; pattern--){

if ((bit == 1) && ((audioByte % pattern) == 0)) {audioByte += 1; } else if ((bit == 0) && ((audioByte % pattern) == 1)) {audioByte -= 1; }}

audioBuffer[bytesPerSample - 1] = audioByte;

stegoStream.Write(audioBuffer, 0, bytesPerSample); }}

audioBuffer = new byte[carrierStream.Length - carrierStream.Position]; carrierStream.Read(audioBuffer, 0, audioBuffer.Length);

stegoStream.Write(audioBuffer, 0, audioBuffer.Length); }

public void Extract(Stream msgStream, Stream StegoKeyStream){ byte[] audioBuffer = new byte[bytesPerSample];

byte msg, bit, audioByte; int msgLength = 0; int keyByte;

while( (msgLength==0 || msgStream.Length<msgLength) ){ msg = 0;

for(int msgIndex=0; msgIndex<8; msgIndex++){ keyByte = GetKeyValue(StegoKeyStream); for(int n=0; n<keyByte-1; n++){

carrierStream.Read(audioBuffer, 0, audioBuffer.Length);} carrierStream.Read(audioBuffer, 0, audioBuffer.Length); audioByte = audioBuffer[bytesPerSample-1];

for (int pattern = 4; pattern >= 1; pattern--){

bit = (byte)(((audioByte % pattern) == 0) ? 0 : 1); msg += (byte)(bit << msgIndex); }}

(7)

if(msgLength==0 && msgStream.Length==4){ msgStream.Seek(0, SeekOrigin.Begin);

msgLength = new BinaryReader(msgStream).ReadInt32(); msgStream.Seek(0, SeekOrigin.Begin);

msgStream.SetLength(0); }}}

//EDH

public void embed(Stream msgStream, Stream StegoKeyStream) { byte[] audioBuffer = new byte[bytesPerSample];

byte message, bit, mixer; int msgBuffer;

int keyByte;

while ((msgBuffer = msgStream.ReadByte()) >= 0) { message = (byte)msgBuffer;

for (int messageIndex = 0; messageIndex < 8; messageIndex++){ keyByte = GetKeyValue(StegoKeyStream);

for (int n = 0; n < keyByte - 1; n++){

carrierStream.Copy(audioBuffer, 0, audioBuffer.Length, stegoStream);}

carrierStream.Read(audioBuffer, 0, audioBuffer.Length); mixer = audioBuffer[bytesPerSample - 1];

byte kernel = mixer;

bit = (byte)(((message & (byte)(1 << messageIndex)) > 0) ? 1 : 0); if ((bit == 1) && ((mixer % 2) == 0) && ((kernel % 2) == 0)) {

mixer += 1; }

else if ((bit == 0) && ((mixer % 2) == 1) && ((kernel % 2) == 1)) { mixer -= 1; } audioBuffer[bytesPerSample - 1] =

mixer; stegoStream.Write(audioBuffer, 0, bytesPerSample); }}

audioBuffer = new byte[carrierStream.Length - carrierStream.Position]; carrierStream.Read(audioBuffer, 0, audioBuffer.Length);

stegoStream.Write(audioBuffer, 0, audioBuffer.Length); }

3. Ekstrak

//LBE

public void Extract(Stream msgStream, Stream StegoKeyStream){ byte[] audioBuffer = new byte[bytesPerSample];

(8)

while( (msgLength==0 || msgStream.Length<msgLength) ){ msg = 0;

for(int msgIndex=0; msgIndex<8; msgIndex++){ keyByte = GetKeyValue(StegoKeyStream); for(int n=0; n<keyByte-1; n++){

carrierStream.Read(audioBuffer, 0, audioBuffer.Length) } carrierStream.Read(audioBuffer, 0, audioBuffer.Length); audioByte = audioBuffer[bytesPerSample-1];

for (int pattern = 4; pattern >= 1; pattern--){

bit = (byte)(((audioByte % pattern) == 0) ? 0 : 1); msg += (byte)(bit << msgIndex); }}

msgStream.WriteByte(msg);

if(msgLength==0 && msgStream.Length==4){ msgStream.Seek(0, SeekOrigin.Begin);

msgLength = new BinaryReader(msgStream).ReadInt32(); msgStream.Seek(0, SeekOrigin.Begin);

msgStream.SetLength(0); }}}

//EDH

public void Extract(Stream msgStream, Stream StegoKeyStream) {byte[] audioBuffer = new byte[bytesPerSample];

byte message, bit, mixer; int messageLength = 0; int keyByte;

while ((messageLength == 0 || msgStream.Length < messageLength)) { message = 0;

for (int messageIndex = 0; messageIndex < 8; messageIndex++){ keyByte = GetKeyValue(StegoKeyStream);

for (int n = 0; n < keyByte - 1; n++){

carrierStream.Read(audioBuffer, 0, audioBuffer.Length); } carrierStream.Read(audioBuffer, 0, audioBuffer.Length); mixer = audioBuffer[bytesPerSample - 1];

byte kernel = mixer;

bit = (byte)(((mixer % 2) == 0 && (kernel % 2 == 0)) ? 0 : 1); message += (byte)(bit << messageIndex); }

msgStream.WriteByte(message);

if (messageLength == 0 && msgStream.Length == 4) { msgStream.Seek(0, SeekOrigin.Begin);

messageLength = new BinaryReader(msgStream).ReadInt32(); msgStream.Seek(0, SeekOrigin.Begin);

(9)

CURRICULUM VITAE

1. Biodata

Nama : Melly

Alamat Sekarang : Jl. H.Misbah Komplek Multatuli Blok D No 16,Medan, Sumatera Utara

Alamat Orang Tua : Jl. Dalil Tani II Gg Jahe No 7, Pematangsiantar, Sumater Utara Telp / HP : 087892094066

Email : [email protected]

2. Riwayat Pendidikan

1999 – 2000 : TK Swasta Methodist Pematangsiantar 2000 – 2007 : SD Swasta Methodist Pematangsiantar 2007 – 2010 : SMP Swasta Methodist Pematangsiantar 2010 – 2013 : SMA Swasta Methodist Pematangsiantar

2013 – Sekarang : Universitas Sumatera Utara (FasilkomTI –Ilmu Komputer)

3. Keahlian

Programming : C# , Visual Basic Database : MySQL.

Software : Ms. Office, Microsoft Visual Studio, Notepad++, Sharp Develop, Eclipse.

(10)

4. Pelatihan

[2015] Nation Building dari Djarum Foundation di Semarang , Indonesia. [2015] Character Building dari Djarum Foundation di Bandung, Indonesia. [2016] Leadership Development dari Djarum Foundation di Jakarta, Indonesia. 5. Seminar dan Workshop

[2013] Seminar Gelora Literasi Teknologi Informasi dan Komunikasi “Si GELITIK” [2013] Seminar What Will You Be?

[2014] Seminar Nasional Literasi Informasi (SENARAI)

[2014] Seminar Campus Marketeers Club - Effective Market Segmentation and Targeting

[2014] Seminar Young People of Character - The Hope of the Future [2015] Seminar Entrepreneurship Elevator to Success

[2015] Workshop Object Oriented Programming

Medan, Juni 2017 Hormat Saya,

Referensi

Dokumen terkait

Pada pengerjaan skripsi dengan judul Perbandingan Steganografi Data Teks ke dalam File Audio Menggunakan Algoritma Least Significant Bit (LSB) dan Modified Least Significant