• Tidak ada hasil yang ditemukan

Analisis Perbandingan Zero Compresion Dengan Difference Coding Pada Kompresi File Audio

N/A
N/A
Protected

Academic year: 2019

Membagikan "Analisis Perbandingan Zero Compresion Dengan Difference Coding Pada Kompresi File Audio"

Copied!
29
0
0

Teks penuh

(1)

LISTING PROGRAM

1. Menu

Public Class frmMenu

Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click

frmHelp.Show() End Sub

Private Sub QuitToolStripMenuItem_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles QuitToolStripMenuItem.Click End

End Sub

Private Sub ZeroCompressionToolStripMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _

ZeroCompressionToolStripMenuItem.Click frmZeroKom.Show()

End Sub

Private Sub DifferenceCodingToolStripMenuItem_Click(ByVal sender As _ System.Object, ByVal e As System.EventArgs) Handles _

DifferenceCodingToolStripMenuItem.Click KomDekom.Show()

End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click frmAbt.Show()

End Sub End Class

2.ZeroKompresi

Imports System.IO

Public Class frmZeroKom

Const PJG_BUFFER As Integer = 4096

Dim sfdTitle, ofdTitle, sfdFilter, ofdFilter As String Dim fsInput, fsOutput As FileStream

Dim csObj As CryptStream

Dim compressObj As ZERO.Zero.Compressor

Dim decompressObj As ZERO.Zero.Decompressor

Dim pesan As New Pesan() Dim Lama As Single

Dim fileHslKompresi As String = "" Dim fileHslDekompresi As String = "" Dim fileHslEnkripsi As String = "" Dim fileHslDekripsi As String = ""

Private Sub comboOperasi_SelectedIndexChanged(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles comboOperasi.SelectedIndexChanged Select Case comboOperasi.SelectedIndex

Case 0

(2)

ofdFilter = "File (*.wav)|*.wav"

sfdFilter = "File hasil Kompresi (*.zc)|*.zc" Case 1

sfdTitle = "Simpan file hasil deKompresi" ofdTitle = "Cari file yang akan dideKompresi" sfdFilter = "Semua file (*.wav)|*.wav"

ofdFilter = "File hasil DeKompresi (*.zc)|*.zc" End Select

If comboOperasi.SelectedIndex >= 0 Then aktifkanKomponen()

'kosongkanTextBox()

cmdFileAsal.Focus() End If

End Sub

Private Sub cmdProses_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdProses.Click

Dim LenKunci As Integer

LenKunci = Len(txtKunci.Text) If LenKunci >= 5 Then

Dim JamAwal As String Dim JamAkhir As String

JamAwal = Format(Now, "hh:mm:ss tt") proses()

Dim fileName1 As String = txtFileAsal.Text Dim fileName2 As String = txtFileTujuan.Text 'Dim fileData As String

Dim rasio As Single, Size1 As Single, Size2 As Single Dim fileDetails1 As System.IO.FileInfo = New

System.IO.FileInfo(fileName1)

Dim fileDetails2 As System.IO.FileInfo = New System.IO.FileInfo(fileName2)

Size1 = fileDetails1.Length.ToString Size2 = fileDetails2.Length.ToString

rasio = (Math.Abs(Size1 - Size2) / Size1) * 100 lblSize1.Text = Size1 & " Bytes"

lblSize2.Text = Size2 & " Bytes" lblRasio.Text = rasio & " %"

List.Items.Add(" Ukuran File Asli Proses: " & comboOperasi.Text & " "_& Size1)

List.Items.Add(" Ukuran File Hasil Proses: " & comboOperasi.Text & " "_& Size2)

List.Items.Add(" Rasio Kompresi: " & rasio & " %") JamAkhir = Format(Now, "hh:mm:ss tt")

Lama = (DateDiff("s", JamAkhir, JamAwal)) List.Items.Add("Waktu: " & Lama & " Detik")

lblLama.Text = Format(Math.Abs(Lama), "00") & " Detik" Else

MsgBox("Panjang Password Harus > 5 char") txtKunci.Focus()

End If

End Sub

Private Sub cmdFileAsal_Click(ByVal sender As System.Object, ByVal e _ As System.EventArgs) Handles cmdFileAsal.Click

openDialog.Title = ofdTitle openDialog.Filter = ofdFilter openDialog.ShowDialog()

(3)

txtFileAsal.Text = openDialog.FileName

List.Items.Add(" Nama File Asli:" & (openDialog.FileName)) cmdFileTujuan.Focus()

End If End Sub

Private Sub cmdFileTujuan_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdFileTujuan.Click

saveDialog.Title = sfdTitle saveDialog.Filter = sfdFilter saveDialog.ShowDialog()

If saveDialog.FileName.Trim <> "" Then

txtFileTujuan.Text = saveDialog.FileName

List.Items.Add(" Nama File Proses:" & (saveDialog.FileName)) txtKunci.Focus()

End If End Sub

Private Sub txtKunci_KeyPress(ByVal sender As Object, ByVal e As _ System.Windows.Forms.KeyPressEventArgs) Handles txtKunci.KeyPress If Asc(e.KeyChar) = 13 Then

proses() End If

End Sub

Private Sub cmdBatal_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdBatal.Click

nonAktifkanKomponen() kosongkanTextBox() End Sub

Private Sub cmdKeluar_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdKeluar.Click

Me.Close() End Sub

#Region "Fungsi dan prosedur" Private Sub proses()

If comboOperasi.SelectedIndex >= 0 And cekMasukanLengkap() Then Select Case comboOperasi.SelectedIndex

Case 0

List.Items.Add("Sedang melakukan kompresi...") kompresiDekompresiBerkas()

List.Items.Add("---> Selesai <---")

pesan.pesanInfo("Kompresi telah dilakukan.", "Informasi") Case 1

List.Items.Add("Sedang melakukan dekompresi...") kompresiDekompresiBerkas()

List.Items.Add("---> Selesai <---")

pesan.pesanInfo("Dekompresi telah dilakukan.", "Informasi") End Select

List.Items.Add("Ok") hapusFileTemporer() nonAktifkanKomponen() End If

End Sub

Private Sub hapusFileTemporer()

Select Case comboOperasi.SelectedIndex Case 0

(4)

Case 1

Dim fileDihapus As New FileInfo(fileHslDekompresi) fileDihapus.Delete()

End Select End Sub

Private Sub enkripsiDekripsiBerkas() Try

Select Case comboOperasi.SelectedIndex Case 0

fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _

FileAccess.Read) Case 1

fsInput = New FileStream(fileHslDekompresi, FileMode.Open, _

FileAccess.Read) End Select

fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _ FileAccess.Read)

Catch ex As IOException

pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub

End Try

Try

Select Case comboOperasi.SelectedIndex Case 0

Dim arrFileTujuan() As String = Split(txtFileAsal.Text,".") fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) & ".tmp" fsOutput = New

FileStream(fileHslEnkripsi,FileMode.OpenOrCreate_,FileAccess.Write) Case 1

fsOutput = New FileStream(txtFileTujuan.Text, _

FileMode.OpenOrCreate, FileAccess.Write) End Select

fsOutput = New FileStream(txtFileTujuan.Text, FileMode.OpenOrCreate,_

FileAccess.Write)

Catch ex As IOException

pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub

End Try

Dim lngPanjangBerkas As Long = fsInput.Length

If lngPanjangBerkas > 2147483647 Then

pesan.pesanError("Ukuran maksimal berkas yang dapat diproses adalah _sebesar 2.147.483.647 bit.", _"Ukuran berkas terlalu besar")

Exit Sub End If

fsOutput.SetLength(0)

Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte

Dim ctr As Int32 = 0

While ctr < chrKunci.Length

bytKunci(ctr) = Convert.ToByte(chrKunci(ctr)) ctr = ctr + 1

(5)

csObj = New CryptStream(fsOutput, fsInput.Length, bytKunci) Dim bytBuffer(PJG_BUFFER - 1) As Byte

Dim lngByteDiproses As Long = 0 Dim intJmlBlok As Integer = 0 ctr = 0

While lngByteDiproses < lngPanjangBerkas

intJmlBlok = fsInput.Read(bytBuffer, 0, PJG_BUFFER)

Select Case comboOperasi.SelectedIndex Case 0

csObj.tulisHasilEnkripsi(bytBuffer, intJmlBlok, PJG_BUFFER, ctr)

Case 1

csObj.tulisHasilDekripsi(bytBuffer, intJmlBlok, PJG_BUFFER, ctr)

End Select ctr = ctr + 1

lngByteDiproses = lngByteDiproses + intJmlBlok

End While

fsInput.Close() fsOutput.Close() End Sub

Private Sub kompresiDekompresiBerkas() Select Case comboOperasi.SelectedIndex Case 0

compressObj = New ZERO.Zero.Compressor(fileHslEnkripsi, _ txtFileTujuan.Text)

compressObj.Kompresi() Case 1

Dim arrFileTujuan() As String = Split(txtFileAsal.Text, ".") fileHslDekompresi = arrFileTujuan(arrFileTujuan.Length - 1) & ".tmp"

decompressObj = New ZERO.Zero.Decompressor(txtFileAsal.Text, _ fileHslDekompresi)

decompressObj.dekompresi() End Select

End Sub

Private Sub aktifkanKomponen() txtFileAsal.Enabled = True txtFileTujuan.Enabled = True txtKunci.Enabled = True cmdFileAsal.Enabled = True cmdFileTujuan.Enabled = True cmdProses.Enabled = True End Sub

Private Sub nonAktifkanKomponen() txtFileAsal.Enabled = False txtFileTujuan.Enabled = False txtKunci.Enabled = False cmdFileAsal.Enabled = False cmdFileTujuan.Enabled = False cmdProses.Enabled = False End Sub

(6)

txtFileTujuan.Clear() txtKunci.Clear() lblSize1.Text = "" lblSize2.Text = "" lblRasio.Text = "" List.Items.Clear() Lama = 0

lblLama.Text = "" End Sub

Private Function cekMasukanLengkap() As Boolean If txtFileAsal.Text.Trim() = "" Then

pesan.pesanError("Nama berkas awal belum diisi.", "Masukan tidak lengkap.") txtFileAsal.Focus()

Return False

ElseIf txtFileTujuan.Text.Trim() = "" Then

pesan.pesanError("Nama berkas tujuan belum diisi.", "Masukan tidak _lengkap.")

txtFileTujuan.Focus() Return False

ElseIf txtKunci.Text.Trim() = "" Then

pesan.pesanError("Kata kunci belum diisi.", "Masukan tidak lengkap.")

txtKunci.Focus() Return False

ElseIf txtKunci.Text.Length < 5 Then

pesan.pesanError("Kata kunci harus terdiri dari minimal karakter.", _"Masukan tidak lengkap.")

txtKunci.Focus() Return False Else

Return True End If

End Function #End Region

Private Sub txtKunci_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtKunci.TextChanged

cmdProses.Enabled = True End Sub

End Class

3. Difference Coding

Imports System.IO

Public Class frmDiffCoding

Const PJG_BUFFER As Integer = 4096

Dim sfdTitle, ofdTitle, sfdFilter, ofdFilter As String Dim fsInput, fsOutput As FileStream

Dim csObj As CryptStream

Dim compressObj As DIFF.Diff.Compressor

Dim decompressObj As DIFF.Diff.Decompressor

Dim pesan As New Pesan()

(7)

Dim Lama As Single

Private Sub comboOperasi_SelectedIndexChanged(ByVal sender As System.Object, _

ByVal e As System.EventArgs) Handles comboOperasi.SelectedIndexChanged Select Case comboOperasi.SelectedIndex

Case 0

sfdTitle = "Simpan file hasil Kompresi" ofdTitle = "Cari File yang akan diKompresi" ofdFilter = "File (*.wav)|*.wav"

sfdFilter = "File hasil Kompresi (*.dc)|*.dc" Case 1

sfdTitle = "Simpan file hasil deKompresi" ofdTitle = "Cari file yang akan dideKompresi" sfdFilter = "Semua file (*.wav)|*.wav"

ofdFilter = "File hasil DeKompresi (*.dc)|*.dc" End Select

If comboOperasi.SelectedIndex >= 0 Then aktifkanKomponen()

kosongkanTextBox() cmdFileAsal.Focus() End If

End Sub

Private Sub cmdProses_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdProses.Click

Dim LenKunci As Integer

LenKunci = Len(txtKunci.Text) If LenKunci >= 5 Then

Dim JamAwal As String Dim JamAkhir As String

JamAwal = Format(Now, "hh:mm:ss tt") proses()

Dim fileName1 As String = txtFileAsal.Text Dim fileName2 As String = txtFileTujuan.Text

Dim rasio As Single, Size1 As Single, Size2 As Single Dim fileDetails1 As System.IO.FileInfo = New

System.IO.FileInfo(fileName1)

Dim fileDetails2 As System.IO.FileInfo = New System.IO.FileInfo(fileName2)

Size1 = fileDetails1.Length.ToString Size2 = fileDetails2.Length.ToString

rasio = (Math.Abs(Size1 - Size2) / Size1) * 100 lblSize1.Text = Size1 & " Bytes"

lblSize2.Text = Size2 & " Bytes" lblRasio.Text = rasio & " %"

List.Items.Add(" Ukuran File Asli Proses: " & comboOperasi.Text & " " & _Size1)

List.Items.Add(" Ukuran File Hasil Proses: " & comboOperasi.Text & " " & _Size2)

List.Items.Add(" Rasio Kompresi: " & rasio & " %") JamAkhir = Format(Now, "hh:mm:ss tt")

Lama = (DateDiff("s", JamAkhir, JamAwal))

lblLama.Text = Format(Math.Abs(Lama), "00") & " Detik" Else

MsgBox("Panjang Password Harus > 5 char") txtKunci.Focus()

(8)

Private Sub cmdFileAsal_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdFileAsal.Click

openDialog.Title = ofdTitle openDialog.Filter = ofdFilter openDialog.ShowDialog()

If openDialog.FileName.Trim <> "" Then txtFileAsal.Text = openDialog.FileName cmdFileTujuan.Focus()

End If End Sub

Private Sub cmdFileTujuan_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdFileTujuan.Click

saveDialog.Title = sfdTitle saveDialog.Filter = sfdFilter saveDialog.ShowDialog()

If saveDialog.FileName.Trim <> "" Then

txtFileTujuan.Text = saveDialog.FileName txtKunci.Focus()

End If End Sub

Private Sub txtKunci_KeyPress(ByVal sender As Object, ByVal e As _ System.Windows.Forms.KeyPressEventArgs) Handles txtKunci.KeyPress If Asc(e.KeyChar) = 13 Then

proses() End If

End Sub

Private Sub cmdBatal_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdBatal.Click

nonAktifkanKomponen() kosongkanTextBox() End Sub

Private Sub cmdKeluar_Click(ByVal sender As System.Object, ByVal e As _ System.EventArgs) Handles cmdKeluar.Click

Me.Close() End Sub

#Region "Fungsi dan prosedur" Private Sub proses()

If comboOperasi.SelectedIndex >= 0 And cekMasukanLengkap() Then Select Case comboOperasi.SelectedIndex

Case 0

enkripsiDekripsiBerkas()

List.Items.Add("Sedang melakukan kompresi...") kompresiDekompresiBerkas()

List.Items.Add("Proses selesai.")

pesan.pesanInfo("Kompresi telah dilakukan.", "Informasi") Case 1

List.Items.Add("Sedang melakukan dekompresi...") kompresiDekompresiBerkas()

enkripsiDekripsiBerkas()

List.Items.Add("Proses selesai.")

pesan.pesanInfo("Dekompresi telah dilakukan.", "Informasi") End Select

List.Items.Add("Aplikasi siap.") hapusFileTemporer()

(9)

End Sub

Private Sub hapusFileTemporer()

Select Case comboOperasi.SelectedIndex Case 0

Dim fileDihapus As New FileInfo(fileHslEnkripsi) fileDihapus.Delete()

Case 1

Dim fileDihapus As New FileInfo(fileHslDekompresi) fileDihapus.Delete()

End Select End Sub

Private Sub enkripsiDekripsiBerkas() Try

Select Case comboOperasi.SelectedIndex Case 0

fsInput = New FileStream(txtFileAsal.Text, FileMode.Open, _

FileAccess.Read) Case 1

fsInput = New FileStream(fileHslDekompresi, FileMode.Open, _

FileAccess.Read) End Select

Catch ex As IOException

pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub

End Try

Try

Select Case comboOperasi.SelectedIndex Case 0

Dim arrFileTujuan() As String = Split(txtFileAsal.Text,".") fileHslEnkripsi = arrFileTujuan(arrFileTujuan.Length - 2) ".tmp" fsOutput = New FileStream(fileHslEnkripsi, FileMode._

OpenOrCreate, FileAccess.Write) Case 1

fsOutput = New FileStream(txtFileTujuan.Text, _

FileMode.OpenOrCreate, FileAccess.Write) End Select

Catch ex As IOException

pesan.pesanError(ex.Message, "Akses berkas ditolak") Exit Sub

End Try

Dim lngPanjangBerkas As Long = fsInput.Length

If lngPanjangBerkas > 2147483647 Then

pesan.pesanError("Ukuran berkas terlalu besar") Exit Sub

End If

fsOutput.SetLength(0)

Dim chrKunci() As Char = txtKunci.Text.ToCharArray() Dim bytKunci(chrKunci.Length - 1) As Byte

Dim ctr As Int32 = 0

While ctr < chrKunci.Length

bytKunci(ctr) = Convert.ToByte(chrKunci(ctr)) ctr = ctr + 1

End While

(10)

Dim bytBuffer(PJG_BUFFER - 1) As Byte Dim lngByteDiproses As Long = 0 Dim intJmlBlok As Integer = 0 ctr = 0

While lngByteDiproses < lngPanjangBerkas

intJmlBlok = fsInput.Read(bytBuffer, 0, PJG_BUFFER) Select Case comboOperasi.SelectedIndex

Case 0

csObj.tulisHasilEnkripsi(bytBuffer, intJmlBlok, PJG_BUFFER,ctr)

Case 1

csObj.tulisHasilDekripsi(bytBuffer, intJmlBlok, PJG_BUFFER,ctr)

End Select ctr = ctr + 1

lngByteDiproses = lngByteDiproses + intJmlBlok End While

fsInput.Close() fsOutput.Close() End Sub

Private Sub kompresiDekompresiBerkas() Select Case comboOperasi.SelectedIndex Case 0

compressObj = New DIFF.Diff.Compressor(fileHslEnkripsi, txtFileTujuan.Text)

compressObj.Kompresi() Case 1

Dim arrFileTujuan() As String = Split(txtFileAsal.Text, ".") fileHslDekompresi = arrFileTujuan(arrFileTujuan.Length - 1) & "._tmp"

decompressObj = New DIFF.Diff.Decompressor(txtFileAsal.Text, _ fileHslDekompresi)

decompressObj.dekompresi() End Select

End Sub

Private Sub aktifkanKomponen() txtFileAsal.Enabled = True txtFileTujuan.Enabled = True txtKunci.Enabled = True cmdFileAsal.Enabled = True cmdFileTujuan.Enabled = True cmdProses.Enabled = True End Sub

Private Sub nonAktifkanKomponen() txtFileAsal.Enabled = False txtFileTujuan.Enabled = False txtKunci.Enabled = False cmdFileAsal.Enabled = False cmdFileTujuan.Enabled = False cmdProses.Enabled = False End Sub

Private Sub kosongkanTextBox() txtFileAsal.Clear()

(11)

txtKunci.Clear() lblRasio.Text = "" lama = 0

lblLama.Text = "" End Sub

Private Function cekMasukanLengkap() As Boolean If txtFileAsal.Text.Trim() = "" Then

pesan.pesanError("Nama berkas awal belum diisi.", _ "Masukan tidak lengkap.")

txtFileAsal.Focus() Return False

ElseIf txtFileTujuan.Text.Trim() = "" Then

pesan.pesanError("Nama berkas tujuan belum diisi.", _ "Masukan tidak lengkap.")

txtFileTujuan.Focus() Return False

ElseIf txtKunci.Text.Trim() = "" Then

pesan.pesanError("Kata kunci belum diisi.", _ "Masukan tidak lengkap.")

txtKunci.Focus() Return False

ElseIf txtKunci.Text.Length < 5 Then

pesan.pesanError("Kata kunci harus terdiri dari minimal 5 karakter.",_

"Masukan tidak lengkap.") txtKunci.Focus()

Return False Else

Return True End If

End Function #End Region End Class

Namespace ZERO

#Region " NAMESPACE : ZERO " Namespace Zero

#Region " CLASS : Compressor " Public Class Compressor

Private Overloads Function Equals(ByVal objA As Object, ByVal objB As_

Object) As Boolean End Function

Private Overloads Function ReferenceEquals(ByVal objA As Object, _

ByVal objB As Object) As Boolean End Function

Public ReadOnly Property Value() As Long Get

Dim lngValue As Long

If Not (Me.fsInput Is Nothing) Then Try

lngValue = Me.fsInput.Position Catch ex As Exception

End Try End If

(12)

End Get End Property

Public ReadOnly Property Length() As Long Get

Static lngLength As Long = -1 If lngLength = -1 Then

Dim fileInfo As New IO.FileInfo(Me.Input) lngLength = fileInfo.Length

End If

Return lngLength End Get

End Property

Private Input As String Private Output As String

Private fsInput As IO.FileStream

Private fsOutput As IO.FileStream

Private bsInput As IO.BufferedStream

Private bsOutput As IO.BufferedStream

Private TreeNodes() As Internal.ZeroTreeNode

Public Sub New(ByVal Input As String, ByVal Output As String) Me.Input = Input

Me.Output = Output End Sub

Public Sub ZerroKomp()

Me.TreeNodes = Zero.Internal.ambilZeroTreeNodes(Me.Input) Zero.Internal.GetZeroTree(Me.TreeNodes)

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output,

IO.FileMode.Create)

Me.bsInput = New IO.BufferedStream(Me.fsInput, _ Zero.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Zero.Internal.pjgBuffer)

Dim strXML As String = Zero.Internal.NodesToString(Me.TreeNodes)

Dim bytXML() As Byte = _

System.Text.Encoding.Default.GetBytes(strXML) 'tulis panjang XML, dalam 10 byte.

Dim xmlLength As String = bytXML.Length.ToString

Do Until xmlLength.Length = 10 : xmlLength = " " & xmlLength : _ Loop

Dim bytXmlLength() As Byte = _

System.Text.Encoding.Default.GetBytes(xmlLength) Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim strZerro As String Dim readByte As Integer Dim JumZerro As Integer Dim KodingZerro As String Do Until readByte = 0

readByte = Me.bsInput.ReadByte If Not readByte = 0 Then

strZerro = strZerro & "0" End If

(13)

CByte(binaryDecimalConverter.GetDecimal(strZerro._ Substring(0, 8)))

Me.bsOutput.WriteByte(byteOut) strZerro = strZerro.Remove(0, 8) End If

Loop End Sub

Public Sub ZerroDekom()

Me.TreeNodes = Zero.Internal.ambilZeroTreeNodes(Me.Input) Zero.Internal.GetZeroTree(Me.TreeNodes)

Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim readByte As Integer

Dim DekodingZerro As String Dim DekodingAllZerro As String Dim ByteZerro As Integer Do Until readByte = "0"

readByte = Me.bsInput.ReadByte If readByte = "0" Then

ByteZerro = Right(readByte, 1) End If

DekodingZerro = ByteZerro * "0" Loop

DekodingAllZerro = DekodingAllZerro & DekodingZerro End Sub

Public Sub Kompresi()

Me.TreeNodes = Zero.Internal.ambilZeroTreeNodes(Me.Input) Zero.Internal.GetZeroTree(Me.TreeNodes)

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output,

IO.FileMode.Create)

Me.bsInput = New IO.BufferedStream(Me.fsInput, _ Zero.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Zero.Internal.pjgBuffer)

Dim strXML As String = Zero.Internal.NodesToString(Me.TreeNodes) Dim bytXML() As Byte = _

System.Text.Encoding.Default.GetBytes(strXML) Dim xmlLength As String = bytXML.Length.ToString Do Until xmlLength.Length = 10 : xmlLength = " " _

& xmlLength : Loop

Dim bytXmlLength() As Byte = _

System.Text.Encoding.Default.GetBytes(xmlLength) Me.bsOutput.Write(bytXmlLength, 0, bytXmlLength.Length) Me.bsOutput.Position += 10

Me.bsOutput.Write(bytXML, 0, bytXML.Length) Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim strBinary As String Dim readByte As Integer Do Until readByte = -1

readByte = Me.bsInput.ReadByte If Not readByte = -1 Then

Dim strPath As String = Me.TreeNodes(readByte).Path strBinary = strBinary & strPath

End If

(14)

CByte(binaryDecimalConverter.GetDecimal(strBinary.Substring(0, 8))) Me.bsOutput.WriteByte(byteOut)

strBinary = strBinary.Remove(0, 8) End If

Loop

If Not strBinary = "" Then

Do Until strBinary.Length = 10 : strBinary = " " & _ strBinary : Loop

Dim bytLeftovers() As Byte = _

System.Text.Encoding.Default.GetBytes(strBinary) Me.bsOutput.Position = 10

Me.bsOutput.Write(bytLeftovers, 0, bytLeftovers.Length) End If

Me.bsInput.Close() Me.bsOutput.Close()

Me.fsInput.Close() Me.fsOutput.Close() End Sub

End Class #End Region

#Region " CLASS : Decompressor " Public Class Decompressor

Private Overloads Function Equals(ByVal objA As Object, ByVal objB As Object) As Boolean

End Function

Private Overloads Function ReferenceEquals(ByVal objA As Object, ByVal objB As Object) As Boolean

End Function

Public ReadOnly Property Value() As Long Get

Dim lngValue As Long

If Not (Me.fsInput Is Nothing) Then Try

lngValue = Me.fsInput.Position Catch ex As Exception

End Try End If

Return lngValue End Get

End Property

Public ReadOnly Property Length() As Long Get

Static lngLength As Long = -1 If lngLength = -1 Then

Dim fileInfo As New IO.FileInfo(Me.Input) lngLength = fileInfo.Length

End If

Return lngLength End Get

End Property

Private Input As String Private Output As String

Private fsInput As IO.FileStream

Private fsOutput As IO.FileStream

Private bsInput As IO.BufferedStream

Private bsOutput As IO.BufferedStream

(15)

Private currentNode As Internal.ZeroTreeNode

Public Sub New(ByVal Input As String, ByVal Output As String) Me.Input = Input

Me.Output = Output End Sub

Public Sub dekompresi()

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output,

IO.FileMode.Create)

Me.bsInput = New IO.BufferedStream(Me.fsInput, _ Zero.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Zero.Internal.pjgBuffer)

Dim bytTreeNodesAsStringLength(9) As Byte

Me.bsInput.Read(bytTreeNodesAsStringLength, 0, _ bytTreeNodesAsStringLength.Length)

Dim treeNodesAsStringLength As Integer = Integer.Parse(System.Text.Encoding.Default.GetString _

(bytTreeNodesAsStringLength).Replace(" ", "")) Dim bytLeftOvers(9) As Byte

Me.bsInput.Read(bytLeftOvers, 0, bytLeftOvers.Length) Dim strLeftovers As String =

System.Text.Encoding.Default.GetString(bytLeftOvers).Replace(" ", "") Dim bytXml(treeNodesAsStringLength - 1) As Byte

Me.bsInput.Read(bytXml, 0, treeNodesAsStringLength) Dim strXML As String =

System.Text.Encoding.Default.GetString(bytXml)

Dim TreeNodes() As Internal.ZeroTreeNode = Zero.Internal.StringToNodes(strXML)

Me.Tree = Zero.Internal.GetZeroTree(TreeNodes) Me.currentNode = Me.Tree

Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim readByte As Integer Do Until (readByte = -1)

readByte = Me.bsInput.ReadByte If Not readByte = -1 Then

Dim strBinary As String = _

binaryDecimalConverter.GetBinary(readByte) Me.dekripsiBits(strBinary)

End If Loop

Me.dekripsiBits(strLeftovers) Me.bsInput.Close()

Me.bsOutput.Close()

Me.fsInput.Close() Me.fsOutput.Close() End Sub

Private Sub dekripsiBits(ByVal Bits As String) Dim x As Integer

For x = 0 To (Bits.Length - 1)

Select Case Bits.Chars(x).ToString Case "0"

Me.currentNode = Me.currentNode.Left Case "1"

(16)

End Select

If Not (Me.currentNode.Character = -1) Then

Me.bsOutput.WriteByte(CByte(Me.currentNode.Character)) Me.currentNode = Me.Tree End If

Next x End Sub End Class #End Region

#Region " CLASS : Internal " Friend Class Internal

Public Const pjgBuffer As Integer = (1024) * 4

#Region " FUNCTION : GetZeroTreeNodes "

Public Shared Function ambilZeroTreeNodes(ByVal File As String) As _

ZeroTreeNode()

Dim ZeroTreeNodes(255) As ZeroTreeNode

Dim x As Integer For x = 0 To 255

ZeroTreeNodes(x) = New ZeroTreeNode

ZeroTreeNodes(x).Character = x Next x

Dim fileStream As New IO.FileStream(File, IO.FileMode.Open) Dim readByte As Integer

Do Until readByte = -1

readByte = fileStream.ReadByte If Not readByte = -1 Then

ZeroTreeNodes(readByte).Weight += 1 End If

Loop

fileStream.Close() Return ZeroTreeNodes End Function

#End Region

#Region " FUNCTION : GetZeroTree "

Public Shared Function GetZeroTree(ByVal TreeNodes() As _

ZeroTreeNode) As ZeroTreeNode

Dim tempTreeNodes() As ZeroTreeNode = CType(TreeNodes.Clone, _

ZeroTreeNode())

Do Until tempTreeNodes.Length = 1

Array.Sort(tempTreeNodes, New ZeroTreeNodeComparer) Dim node1 As ZeroTreeNode =

tempTreeNodes(tempTreeNodes._ Length - 1)

Dim node2 As ZeroTreeNode = tempTreeNodes(tempTreeNodes._

Length - 2)

Dim newNode As New ZeroTreeNode

newNode.Character = -1

newNode.Weight = node1.Weight + node2.Weight newNode.Left = node1

(17)

node1.Parent = newNode node2.Parent = newNode

ReDim Preserve tempTreeNodes(tempTreeNodes.Length - 3) ReDim Preserve tempTreeNodes(tempTreeNodes.Length) tempTreeNodes(tempTreeNodes.Length - 1) = newNode Loop

Return tempTreeNodes(0) End Function

#End Region

#Region " FUNCTION : NodesToString/StringToNodes "

Public Shared Function NodesToString(ByVal TreeNodes() As _

ZeroTreeNode) As String Dim characters(255) As String Dim weights(255) As String Dim x As Integer

For x = 0 To 255

characters(x) = CStr(TreeNodes(x).Character) weights(x) = CStr(TreeNodes(x).Weight) Next x

Return String.Join("#", characters) & "%" & String.Join("#", weights)

End Function

Public Shared Function StringToNodes(ByVal Xml As String) As _

ZeroTreeNode()

Dim characters() As String = _

Xml.Split("%".ToCharArray)(0).Split("#".ToCharArray) Dim weights() As String = _

Xml.Split("%".ToCharArray)(1).Split("#".ToCharArray) Dim TreeNodes(255) As ZeroTreeNode

Dim x As Integer For x = 0 To 255

TreeNodes(x) = New ZeroTreeNode

TreeNodes(x).Character = CInt(characters(x)) TreeNodes(x).Weight = CLng(weights(x)) Next x

Return TreeNodes End Function

#End Region

#Region " CLASS : ZeroTreeNode " Public Class ZeroTreeNode

Public Sub New() End Sub

Private Shadows Function Equals() As Boolean Return False

End Function

Private Shadows Function ReferenceEquals() As Boolean Return False

End Function

Public Character As Integer = -1

Public Weight As Long = 0

<System.Xml.Serialization.XmlIgnore()> Public Parent As ZeroTreeNode <System.Xml.Serialization.XmlIgnore()> Public Left As ZeroTreeNode

<System.Xml.Serialization.XmlIgnore()> Public Right As _

ZeroTreeNode

(18)

Get

Static strPath As String If strPath Is Nothing Then

If Not (Me.Parent Is Nothing) Then

If (Me.Parent.Left Is Me) Then strPath = "0" If (Me.Parent.Right Is Me) Then strPath ="1" strPath = Parent.Path & strPath

End If End If

Return strPath End Get

End Property End Class

#End Region

#Region " CLASS : ZeroTreeNodeComparer " Public Class ZeroTreeNodeComparer

Implements IComparer

Public Sub New() End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare Dim returnVal As Integer = -1

Dim a As Double = CType(x, ZeroTreeNode).Weight Dim b As Double = CType(y, ZeroTreeNode).Weight If a > b Then

returnVal = 1 ElseIf a < b Then returnVal = -1 ElseIf a = b Then returnVal = 0 End If

returnVal *= -1 Return returnVal End Function

End Class #End Region

#Region " CLASS : BinaryDecimalConverter " Public Class BinaryDecimalConverter

Private hashGetDecimal As Hashtable

Private hashGetBinary As Hashtable

Public Function GetDecimal(ByVal strBinary As String) As Integer

If Me.hashGetDecimal Is Nothing Then Me.hashGetDecimal = New Hashtable

Dim x As Integer For x = 0 To 255

Me.hashGetDecimal(Me.GetBinaryInternal(x)) = x Next x

End If

Return CInt(Me.hashGetDecimal(strBinary)) End Function

Public Function GetBinary(ByVal intDecimal As Integer) As String

If Me.hashGetBinary Is Nothing Then Me.hashGetBinary = New Hashtable

Dim x As Integer For x = 0 To 255

Me.hashGetBinary(x) = Me.GetBinaryInternal(x) Next x

End If

(19)

End Function

Private Function GetBinaryInternal(ByVal intDecimal AS Integer) As String

Dim Y As Integer

Dim strBinary As String

While (intDecimal \ 2) > 0 Y = intDecimal \ 2 If intDecimal > 1 Then

strBinary = Val(CStr(intDecimal - (Y * 2))) & _ strBinary

End If

intDecimal = Y End While

strBinary = intDecimal & strBinary Do Until strBinary.Length = 8 strBinary = "0" & strBinary Loop

Return strBinary End Function

Private Function GetDecimalInternal(ByVal strBinary As String) As Integer

Dim sngNumber As Integer Dim x As Integer

Dim Tmp As Integer Dim Output As Integer

sngNumber = CInt(strBinary)

For x = 0 To Len(CStr(sngNumber)) - 1 Tmp = CInt(Right(CStr(sngNumber), 1)) If Tmp = 1 Then

Tmp = CInt(Tmp * Math.Pow(2, x)) End If

Output = Output + Tmp Tmp = 1

If Len(CStr(sngNumber)) > 1 Then

sngNumber = CInt(Left(CStr(sngNumber), _ Len(CStr(sngNumber)) - 1))

Else

sngNumber = 0 End If

Next

Return Output End Function

Private Function GetPowerInternal(ByRef Value As Integer, _ ByRef Power As Integer) As Integer

Dim result As Integer If Power > 1 Then Dim x As Integer For x = 2 To Power Value = Value * 2 Next

result = Value Else

If Power = 0 Then result = 1 If Power = 1 Then result = Value End If

(20)

#End Region End Class #End Region End Namespace #End Region End Namespace

6. ModDifference

Namespace DIFF

#Region " NAMESPACE : DIFF " Namespace Diff

#Region " CLASS : Compressor " Public Class Compressor

Private Overloads Function Equals(ByVal objA As Object, ByVal objB _

As Object) As Boolean End Function

Private Overloads Function ReferenceEquals(ByVal objA As Object, _ ByVal objB As Object) As Boolean

End Function

Public ReadOnly Property Value() As Long Get

Dim lngValue As Long

If Not (Me.fsInput Is Nothing) Then Try

lngValue = Me.fsInput.Position Catch ex As Exception

End Try End If

Return lngValue End Get

End Property

Public ReadOnly Property Length() As Long Get

Static lngLength As Long = -1 If lngLength = -1 Then

Dim fileInfo As New IO.FileInfo(Me.Input) lngLength = fileInfo.Length

End If

Return lngLength End Get

End Property

Private Input As String Private Output As String

Private fsInput As IO.FileStream

Private fsOutput As IO.FileStream

Private bsInput As IO.BufferedStream

Private bsOutput As IO.BufferedStream

Private TreeNodes() As Internal.DIFFTreeNode

Public Sub New(ByVal Input As String, ByVal Output As String) Me.Input = Input

Me.Output = Output End Sub

Public Sub KompresiDiff()

(21)

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output, IO.FileMode.Create) Me.bsInput = New IO.BufferedStream(Me.fsInput, _

Diff.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Diff.Internal.pjgBuffer)

Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim readByte As Integer Dim readBit1 As Integer Dim readBit2 As Integer Dim DiffReadBit As Integer Dim IntPosisi As Integer Dim KodingByte As String Dim KodingAllByte As String Do Until readByte = -1

IntPosisi = IntPosisi + 1 readByte = Me.bsInput.ReadByte readBit1 = Left(readByte, 1)

readBit2 = Mid(readByte, IntPosisi, 1) DiffReadBit = readBit2 - readBit1 KodingByte = readBit1 & DiffReadBit Loop

KodingAllByte = KodingAllByte & KodingByte End Sub

Public Sub DeKompresiDiff()

Me.TreeNodes = Diff.Internal.ambilDIFFTreeNodes(Me.Input) Diff.Internal.GetDIFFTree(Me.TreeNodes)

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output, IO.FileMode.Create) Me.bsInput = New IO.BufferedStream(Me.fsInput, _

Diff.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Diff.Internal.pjgBuffer)

Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim readByte As Integer Dim readBit1 As Integer Dim readBit2 As Integer Dim DiffReadBit As Integer Dim IntPosisi As Integer Dim DeKodingByte As String Dim DeKodingAllByte As String Do Until readByte = -1

IntPosisi = IntPosisi + 1 readByte = Me.bsInput.ReadByte readBit1 = Left(readByte, 1)

readBit2 = Mid(readByte, IntPosisi, 1) DiffReadBit = readBit2 + readBit1 DeKodingByte = DiffReadBit

Loop

DeKodingAllByte = DeKodingAllByte & DeKodingByte End Sub

Public Sub Kompresi()

Me.TreeNodes = Diff.Internal.ambilDIFFTreeNodes(Me.Input) Diff.Internal.GetDIFFTree(Me.TreeNodes)

(22)

Me.bsInput = New IO.BufferedStream(Me.fsInput, _ Diff.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Diff.Internal.pjgBuffer)

Dim strXML As String = Diff.Internal.NodesToString(Me.TreeNodes) Dim bytXML() As Byte =

System.Text.Encoding.Default.GetBytes(strXML)

Dim xmlLength As String = bytXML.Length.ToString

Do Until xmlLength.Length = 10 : xmlLength = " " & xmlLength : Loop

Dim bytXmlLength() As Byte = _

System.Text.Encoding.Default.GetBytes(xmlLength) Me.bsOutput.Write(bytXmlLength, 0, bytXmlLength.Length) Me.bsOutput.Position += 10

Me.bsOutput.Write(bytXML, 0, bytXML.Length) Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim strBinary As String Dim readByte As Integer Do Until readByte = -1

readByte = Me.bsInput.ReadByte If Not readByte = -1 Then

Dim strPath As String = Me.TreeNodes(readByte).Path strBinary = strBinary & strPath

End If

If strBinary.Length > 8 Then Dim byteOut As Byte = _

CByte(binaryDecimalConverter.GetDecimal(strBinary.Substring(0, 8)))

Me.bsOutput.WriteByte(byteOut) strBinary = strBinary.Remove(0, 8) End If

Loop

If Not strBinary = "" Then

Do Until strBinary.Length = 10 : strBinary = " " & strBinary : _

Loop

Dim bytLeftovers() As Byte = _

System.Text.Encoding.Default.GetBytes(strBinary) Me.bsOutput.Position = 10

Me.bsOutput.Write(bytLeftovers, 0, bytLeftovers.Length) End If

Me.bsInput.Close() Me.bsOutput.Close() Me.fsInput.Close() Me.fsOutput.Close() End Sub

End Class #End Region

#Region " CLASS : Decompressor " Public Class Decompressor

Private Overloads Function Equals(ByVal objA As Object, ByVal objB As Object) As Boolean

End Function

Private Overloads Function ReferenceEquals(ByVal objA As Object, ByVal objB As Object) As Boolean

(23)

Public ReadOnly Property Value() As Long Get

Dim lngValue As Long

If Not (Me.fsInput Is Nothing) Then Try

lngValue = Me.fsInput.Position Catch ex As Exception

End Try End If

Return lngValue End Get

End Property

Public ReadOnly Property Length() As Long Get

Static lngLength As Long = -1 If lngLength = -1 Then

Dim fileInfo As New IO.FileInfo(Me.Input) lngLength = fileInfo.Length

End If

Return lngLength End Get

End Property

Private Input As String Private Output As String

Private fsInput As IO.FileStream

Private fsOutput As IO.FileStream

Private bsInput As IO.BufferedStream

Private bsOutput As IO.BufferedStream

Private Tree As Internal.DIFFTreeNode

Private currentNode As Internal.DIFFTreeNode

Public Sub New(ByVal Input As String, ByVal Output As String) Me.Input = Input

Me.Output = Output End Sub

Public Sub dekompresi()

Me.fsInput = New IO.FileStream(Me.Input, IO.FileMode.Open) Me.fsOutput = New IO.FileStream(Me.Output, IO.FileMode.Create) Me.bsInput = New IO.BufferedStream(Me.fsInput, _

Diff.Internal.pjgBuffer)

Me.bsOutput = New IO.BufferedStream(Me.fsOutput, _ Diff.Internal.pjgBuffer)

Dim bytTreeNodesAsStringLength(9) As Byte

Me.bsInput.Read(bytTreeNodesAsStringLength, 0, _ bytTreeNodesAsStringLength.Length)

Dim treeNodesAsStringLength As Integer = _ Integer.Parse(System.Text.Encoding.Default.GetString _ (bytTreeNodesAsStringLength).Replace(" ", ""))

Dim bytLeftOvers(9) As Byte

Me.bsInput.Read(bytLeftOvers, 0, bytLeftOvers.Length) Dim strLeftovers As String = _

System.Text.Encoding.Default.GetString(bytLeftOvers).Replace(" ", "")_

Dim bytXml(treeNodesAsStringLength - 1) As Byte Me.bsInput.Read(bytXml, 0, treeNodesAsStringLength) Dim strXML As String =

System.Text.Encoding.Default.GetString(bytXml)

(24)

Me.Tree = Diff.Internal.GetDIFFTree(TreeNodes) Me.currentNode = Me.Tree

Dim binaryDecimalConverter As New

Internal.BinaryDecimalConverter

Dim readByte As Integer Do Until (readByte = -1)

readByte = Me.bsInput.ReadByte If Not readByte = -1 Then

Dim strBinary As String = _

binaryDecimalConverter.GetBinary(readByte) Me.dekripsiBits(strBinary)

End If Loop

Me.dekripsiBits(strLeftovers) Me.bsInput.Close()

Me.bsOutput.Close() Me.fsInput.Close() Me.fsOutput.Close() End Sub

Private Sub dekripsiBits(ByVal Bits As String) Dim x As Integer

For x = 0 To (Bits.Length - 1)

Select Case Bits.Chars(x).ToString Case "0"

Me.currentNode = Me.currentNode.Left Case "1"

Me.currentNode = Me.currentNode.Right End Select

If Not (Me.currentNode.Character = -1) Then

Me.bsOutput.WriteByte(CByte(Me.currentNode.Character)) Me.currentNode = Me.Tree

End If Next x End Sub End Class #End Region

#Region " CLASS : Internal " Friend Class Internal

Public Const pjgBuffer As Integer = (1024) * 4

#Region " FUNCTION : GetDIFFTreeNodes "

Public Shared Function ambilDIFFTreeNodes(ByVal File As _ String) As DIFFTreeNode()

Dim DIFFTreeNodes(255) As DIFFTreeNode

Dim x As Integer For x = 0 To 255

DIFFTreeNodes(x) = New DIFFTreeNode

DIFFTreeNodes(x).Character = x Next x

Dim fileStream As New IO.FileStream(File, IO.FileMode.Open) Dim readByte As Integer

Do Until readByte = -1

(25)

DIFFTreeNodes(readByte).Weight += 1 End If

Loop

fileStream.Close() Return DIFFTreeNodes End Function

#End Region

#Region " FUNCTION : GetDIFFTree "

Public Shared Function GetDIFFTree(ByVal TreeNodes() As

DIFFTreeNode) _

As DIFFTreeNode

Dim tempTreeNodes() As DIFFTreeNode = CType(TreeNodes.Clone, _

DIFFTreeNode())

Do Until tempTreeNodes.Length = 1

Array.Sort(tempTreeNodes, New DIFFTreeNodeComparer) Dim node1 As DIFFTreeNode =

tempTreeNodes(tempTreeNodes.Length - _ 1)

Dim node2 As DIFFTreeNode = tempTreeNodes(tempTreeNodes.Length - _

2)

Dim newNode As New DIFFTreeNode

newNode.Character = -1

newNode.Weight = node1.Weight + node2.Weight newNode.Left = node1

newNode.Right = node2 node1.Parent = newNode node2.Parent = newNode

ReDim Preserve tempTreeNodes(tempTreeNodes.Length - 3) ReDim Preserve tempTreeNodes(tempTreeNodes.Length) tempTreeNodes(tempTreeNodes.Length - 1) = newNode Loop

Return tempTreeNodes(0) End Function

#End Region

#Region " FUNCTION : NodesToString/StringToNodes "

Public Shared Function NodesToString(ByVal TreeNodes() As

DIFFTreeNode)_

As String

Dim characters(255) As String Dim weights(255) As String Dim x As Integer

For x = 0 To 255

characters(x) = CStr(TreeNodes(x).Character) weights(x) = CStr(TreeNodes(x).Weight) Next x

Return String.Join("#", characters) & "%" & String.Join("#", weights)

End Function

Public Shared Function StringToNodes(ByVal Xml As String) As _

DIFFTreeNode()

Dim characters() As String = _

Xml.Split("%".ToCharArray)(0).Split("#".ToCharArray) Dim weights() As String = _

Xml.Split("%".ToCharArray)(1).Split("#".ToCharArray) Dim TreeNodes(255) As DIFFTreeNode

(26)

TreeNodes(x) = New DIFFTreeNode

TreeNodes(x).Character = CInt(characters(x)) TreeNodes(x).Weight = CLng(weights(x)) Next x

Return TreeNodes End Function

#End Region

#Region " CLASS : DIFFTreeNode " Public Class DIFFTreeNode

Public Sub New() End Sub

Private Shadows Function Equals() As Boolean Return False

End Function

Private Shadows Function ReferenceEquals() As Boolean Return False

End Function

Public Character As Integer = -1 Public Weight As Long = 0

<System.Xml.Serialization.XmlIgnore()> Public Parent As

DIFFTreeNode

<System.Xml.Serialization.XmlIgnore()> Public Left As

DIFFTreeNode

<System.Xml.Serialization.XmlIgnore()> Public Right As

DIFFTreeNode

<System.Xml.Serialization.XmlIgnore()> Public ReadOnly _ Property Path() As String

Get

Static strPath As String If strPath Is Nothing Then

If Not (Me.Parent Is Nothing) Then

If (Me.Parent.Left Is Me) Then strPath = "0" If (Me.Parent.Right Is Me) Then strPath = "1" strPath = Parent.Path & strPath

End If End If

Return strPath End Get

End Property End Class

#End Region

#Region " CLASS : DIFFTreeNodeComparer " Public Class DIFFTreeNodeComparer

Implements IComparer

Public Sub New() End Sub

Public Function Compare(ByVal x As Object, ByVal y As Object) As Integer Implements System.Collections.IComparer.Compare

Dim returnVal As Integer = -1

Dim a As Double = CType(x, DIFFTreeNode).Weight Dim b As Double = CType(y, DIFFTreeNode).Weight If a > b Then

returnVal = 1 ElseIf a < b Then returnVal = -1 ElseIf a = b Then returnVal = 0 End If

(27)

End Function End Class

#End Region

#Region " CLASS : BinaryDecimalConverter " Public Class BinaryDecimalConverter

Private hashGetDecimal As Hashtable

Private hashGetBinary As Hashtable

Public Function GetDecimal(ByVal strBinary As String) As Integer If Me.hashGetDecimal Is Nothing Then

Me.hashGetDecimal = New Hashtable

Dim x As Integer For x = 0 To 255

Me.hashGetDecimal(Me.GetBinaryInternal(x)) = x Next x

End If

Return CInt(Me.hashGetDecimal(strBinary)) End Function

Public Function GetBinary(ByVal intDecimal As Integer) As String If Me.hashGetBinary Is Nothing Then

Me.hashGetBinary = New Hashtable

Dim x As Integer For x = 0 To 255

Me.hashGetBinary(x) = Me.GetBinaryInternal(x) Next x

End If

Return CStr(Me.hashGetBinary(intDecimal)) End Function

Private Function GetBinaryInternal(ByVal intDecimal As Integer) As String

Dim Y As Integer

Dim strBinary As String

While (intDecimal \ 2) > 0 Y = intDecimal \ 2 If intDecimal > 1 Then

strBinary = Val(CStr(intDecimal - (Y * 2))) & strBinary End If

intDecimal = Y End While

strBinary = intDecimal & strBinary Do Until strBinary.Length = 8 strBinary = "0" & strBinary Loop

Return strBinary End Function

Private Function GetDecimalInternal(ByVal strBinary As String) As Integer Dim sngNumber As Integer

Dim x As Integer Dim Tmp As Integer Dim Output As Integer

sngNumber = CInt(strBinary)

For x = 0 To Len(CStr(sngNumber)) - 1 Tmp = CInt(Right(CStr(sngNumber), 1)) If Tmp = 1 Then

Tmp = CInt(Tmp * Math.Pow(2, x)) End If

Output = Output + Tmp Tmp = 1

(28)

sngNumber = CInt(Left(CStr(sngNumber), _ Len(CStr(sngNumber)) - 1))

Else

sngNumber = 0 End If

Next

Return Output End Function

Private Function GetPowerInternal(ByRef Value As Integer, ByRef Power As Integer) As Integer

Dim result As Integer If Power > 1 Then Dim x As Integer For x = 2 To Power Value = Value * 2 Next

result = Value Else

If Power = 0 Then result = 1 If Power = 1 Then result = Value End If

Return result End Function End Class

(29)

CURRICULUM VITAE

Data Pribadi

Nama

: Dessy Febriani Triajiwati

Alamat sekarang : Jl.Setia Budi Gang. Marto No.4 Medan

Alamat Orang Tua : Jl. Bubu Gang.Bangun No.5 Medan

Tempat/Tgl Lahir : Medan/ 15 Februari 1990

Telp/ Hp

: 08116150050

Email

Riwayat Pendidikan

1996-2002

: SD Negri 0804877 Medan

2002-2005

: SMP Negri 12 Medan

2005-2008

: SMA Kartika I-1 Medan

2008-2011

: DIII Teknik Informatika Universitas Sumatera Utara

2011-2014

: Ekstensi S1 Ilmu Komputer Universitas Sumatera

Utara

Keahlian/Kursus yang di ikuti :

1.Mampu Mengoperasikan aplikasi dasar computer

Referensi

Dokumen terkait

Private Sub menuUtama_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load. TabControl1.Width = Me.Width

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click. Dim Cmd As

Private Sub btnExitSmpNS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExitSmpNS.Click.. GroupBoxTransaksiSimpananNonSaham.Visible = False

Private Sub BtnKeluar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click. Me.Close()

Private Sub btn_h_Click( ByVal sender As System.. EventArgs ) Handles MyBase .Load. awal() bobot()

Private Sub HelpToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles HelpToolStripMenuItem.Click. frmHelp.Show()

Private Sub LogoutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LogoutToolStripMenuItem.Click. End End Sub

Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click. End