LISTING PROGRAM
Kode Program Form Utama
Imports Microsoft.Office.Interop.Word Imports System.IO
Imports System.Diagnostics
Imports VB = Microsoft.VisualBasic Imports System.Xml
Imports Ionic.Zip
Imports System.Reflection
Public Class frmMain
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCom.Click
Dim i As Integer Dim ln As Integer Dim sw As Stopwatch sw = Stopwatch.StartNew()
intext = System.Text.Encoding.Default.GetBytes(txtInput.Text) Call Kompresi(intext)
txtOutput.Text = "" ln = UBound(outtext) If ln < MAX_LENGTH Then For i = 0 To ln
txtOutput.Text = txtOutput.Text & Chr(outtext(i)) Next
Else
txtOutput.Text = "Isi file tidak muat pada text area" End If
sw.Stop()
txtBFakhir.Text = "0"
txtPKakhir.Text = txtOutput.Text.Length
txtWaktu.Text = sw.ElapsedMilliseconds.ToString() btnSave.Enabled = True
dlgSave.Filter = "DMC File (*.dmc)|*.dmc" MsgBox("Kompresi selesai!!")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDecom.Click
intext = System.Text.Encoding.Default.GetBytes(txtInput.Text) Call Dekompresi(intext)
txtOutput.Text = "" ln = UBound(outtext) If ln < MAX_LENGTH Then For i = 0 To ln
txtOutput.Text = txtOutput.Text & Chr(outtext(i)) Next
Else
txtOutput.Text = "Isi file tidak muat pada text area" End If
sw.Stop()
txtBFakhir.Text = "0"
txtPKakhir.Text = txtOutput.Text.Length
txtWaktu.Text = sw.ElapsedMilliseconds.ToString()
btnSave.Enabled = True
dlgSave.Filter = " DOCX File (*.docx)|*.docx|ODT File (*.odt)|*.odt"
MsgBox("Dekompresi selesai!!") End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOpen.Click
Dim strfilename As String
dlgOpen.Filter = "DOCX File (*.docx)|*.docx|ODT File (*.odt)|*.odt|DMC File (*.dmc)|*.dmc"
Dim dr As Integer = dlgOpen.ShowDialog() strfilename = dlgOpen.FileName
If dr = DialogResult.OK Then txtInput.Text = ""
Dim formatfile As String = Path.GetExtension(strfilename).ToLower() If formatfile = ".txt" Then
Dim fs As FileStream
fs = New FileStream(strfilename, FileMode.Open, FileAccess.Read) Dim sr As StreamReader
sr = New StreamReader(fs)
sr.BaseStream.Seek(0, SeekOrigin.Begin) While sr.Peek() > -1
txtInput.Text = txtInput.Text & sr.ReadLine() End While
sr.Close()
ElseIf formatfile = ".odt" Then
Dim odsZipFile As ZipFile = ZipFile.Read(strfilename)
Dim contentZipEntry As ZipEntry = odsZipFile("content.xml") Dim contentStream As Stream = New MemoryStream() contentZipEntry.Extract(contentStream)
contentStream.Seek(0, SeekOrigin.Begin)
Dim contentXml As XmlDocument = New XmlDocument() contentXml.Load(contentStream)
Dim xmlnode As XmlNodeList Dim i As Integer
xmlnode = contentXml.GetElementsByTagName("text:p") For i = 0 To xmlnode.Count - 1
If i > 0 Then
txtInput.Text = txtInput.Text & " " End If
txtInput.Text = txtInput.Text & xmlnode(i).ChildNodes.Item(0).InnerText Next
contentStream.Close() btnDecom.Enabled = False btnCom.Enabled = True
ElseIf formatfile = ".doc" Or formatfile = ".docx" Then
Dim wordapp As Microsoft.Office.Interop.Word.Application = New Application()
Dim miss As Object = System.Reflection.Missing.Value Dim path As Object = strfilename
Dim readon As Object = True Dim docs As Document
docs = wordapp.Documents.Open(path, miss, readon, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss, miss)
Dim i As Integer Dim totaltext As String totaltext = ""
For i = 0 To docs.Paragraphs.Count - 1
totaltext += docs.Paragraphs(i + 1).Range.Text.ToString().Trim() Next
wordapp.Quit()
txtInput.Text = totaltext btnDecom.Enabled = False btnCom.Enabled = True
ElseIf formatfile = ".dmc" Then Dim num As Short
Dim i As Integer
num = FreeFile()
FileOpen(num, strfilename, OpenMode.Binary) fileLength = LOF(num) - 1
ReDim intext(fileLength) FileGet(num, intext) FileClose(num)
If fileLength < MAX_LENGTH Then For i = 0 To fileLength
txtInput.Text = txtInput.Text & Chr(intext(i)) Next
End If
btnDecom.Enabled = True btnCom.Enabled = False End If
Dim info As New FileInfo(strfilename) txtPKawal.Text = txtInput.Text.Length txtBFawal.Text = info.Length
btnSave.Enabled = False End If
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Dim strfilename As String Dim content As String Dim ln As Integer
Dim dr As Integer = dlgSave.ShowDialog() strfilename = dlgSave.FileName
content = ""
If dr = DialogResult.OK Then
Dim formatfile As String = Path.GetExtension(strfilename).ToLower() If formatfile = ".dmc" Then
ln = UBound(outtext) For i = 0 To ln
content = content & Chr(outtext(i)) Next
FileOpen(1, strfilename, OpenMode.Output) For i = 1 To 1
Print(1, content) Next
FileClose(1)
ElseIf formatfile = ".txt" Then
File.WriteAllText(strfilename, txtOutput.Text)
Dim wordapp = New Application Dim oDoc = wordapp.Documents.Add Dim par1 = oDoc.Content.Paragraphs.Add par1.Range.Text = txtOutput.Text
oDoc.SaveAs(strfilename) oDoc.Close()
wordapp.Quit()
ElseIf formatfile = ".odt" Then
Dim templateFile As ZipFile = ZipFile.Read("template.odt") Dim contentZipEntry As ZipEntry = templateFile("content.xml") Dim contentStream As Stream = New MemoryStream()
contentZipEntry.Extract(contentStream) contentStream.Seek(0, SeekOrigin.Begin)
Dim contentXml As XmlDocument = New XmlDocument() contentXml.Load(contentStream)
contentXml.PreserveWhitespace = True Dim xmlnode As XmlNodeList
xmlnode = contentXml.GetElementsByTagName("text:p") xmlnode(0).ChildNodes.Item(0).InnerText = txtOutput.Text templateFile.RemoveEntry("content.xml")
Dim memStream As MemoryStream = New MemoryStream() contentXml.Save(memStream)
memStream.Seek(0, SeekOrigin.Begin)
templateFile.AddEntry("content.xml", memStream) templateFile.Save(strfilename)
contentStream.Close() memStream.Close() End If
Dim info As New FileInfo(strfilename) txtBFakhir.Text = info.Length
txtRasio.Text = Math.Round((Val(txtBFawal.Text) / Val(txtBFakhir.Text)) * 100, 2) MsgBox("Simpan file selesai!!")
End If
End Sub
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReset.Click
txtBFawal.Text = "0" txtPKakhir.Text = "0" txtPKawal.Text = "0" txtRasio.Text = "0" txtWaktu.Text = "0" End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
btnDecom.Enabled = False btnCom.Enabled = False txtInput.Text = "" txtOutput.Text = "" btnSave.Enabled = False txtBFakhir.Text = "0" txtBFawal.Text = "0" txtPKakhir.Text = "0" txtPKawal.Text = "0" txtRasio.Text = "0" txtWaktu.Text = "0" End Sub
Private Sub TentangToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TentangToolStripMenuItem.Click
frmTentang.ShowDialog() End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close() End Sub End Sub
Private Sub frmMain_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
cover.Close() End Sub
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub txtRasio_TextChanged(sender As Object, e As EventArgs) Handles txtRasio.TextChanged
Kode Program Class Algoritma DMC
Module mainmod
Public Const MAX_LENGTH As Integer = 30000 Public intext(), outtext(), OutByteBuf As Byte Private OutPos, OutBitCount As Integer Private Const MaxBits As Integer = 24
Public Sub Kompresi(ByRef listarr() As Byte)
Dim InpPos, MinValue, MaxValue, RangValue, MidValue, Index, TopBit, One(256), Zero(256), i As Integer
Dim mChar, Bitset As Byte ReDim outtext(500)
OutPos = OutBitCount = OutByteBuf = MinValue = InpPos = 0 MaxValue = (2 ^ MaxBits) - 1
TopBit = 2 ^ (MaxBits - 1)
Do While InpPos <= UBound(listarr) mChar = listarr(InpPos)
InpPos = InpPos + 1 For i = 0 To 7
Bitset = (mChar And (2 ^ (7 - i))) And &HFF Index = (2 ^ i) - 1 + Int(mChar / (2 ^ (8 - i))) RangValue = MaxValue - MinValue
MidValue = MinValue + (RangValue * (Zero(Index) / (One(Index) + Zero(Index))))
If MidValue = MinValue Then MidValue = MidValue + 1 If MidValue = MaxValue - 1 Then MidValue = MidValue - 1
If Bitset > 0 Then
MinValue = MidValue One(Index) = One(Index) + 1 Else
MaxValue = MidValue
Zero(Index) = Zero(Index) + 1 End If
Do While (MaxValue And TopBit) = (MinValue And TopBit) Or MinValue > MaxValue - 255
outtext(OutPos) = OutByteBuf OutBitCount = 0
OutByteBuf = 0 OutPos = OutPos + 1
If OutPos > UBound(outtext) Then ReDim Preserve outtext(OutPos + 500) End If
End If Else
OutByteBuf = OutByteBuf * 2 + 1 OutBitCount = OutBitCount + 1 If OutBitCount = 8 Then
outtext(OutPos) = OutByteBuf OutBitCount = 0
OutByteBuf = 0 OutPos = OutPos + 1
If OutPos > UBound(outtext) Then ReDim Preserve outtext(OutPos + 500) End If
End If End If
MaxValue = (MaxValue And (TopBit - 1)) * 2 + 1 MinValue = (MinValue And (TopBit - 1)) * 2 If MinValue >= MaxValue Then
MaxValue = (2 ^ MaxBits) - 1 End If
Loop Next Loop
For i = MaxBits - 1 To 0 Step -1 If (MinValue And 2 ^ i) = 0 Then OutByteBuf = OutByteBuf * 2 + 0 OutBitCount = OutBitCount + 1 If OutBitCount = 8 Then
outtext(OutPos) = OutByteBuf OutBitCount = 0
OutByteBuf = 0 OutPos = OutPos + 1
If OutPos > UBound(outtext) Then
ReDim Preserve outtext(OutPos + 500) End If
End If Else
outtext(OutPos) = OutByteBuf OutBitCount = 0
OutByteBuf = 0 OutPos = OutPos + 1
If OutPos > UBound(outtext) Then
ReDim Preserve outtext(OutPos + 500) End If
End If Next
Do While OutBitCount > 0
OutByteBuf = OutByteBuf * 2 + 1 OutBitCount = OutBitCount + 1 If OutBitCount = 8 Then
outtext(OutPos) = OutByteBuf OutBitCount = 0
OutByteBuf = 0 OutPos = OutPos + 1
Public Sub Dekompresi(ByRef listarr() As Byte) Dim InpPos As Integer
Dim InBitPos As Integer Dim MinValue As Integer Dim MaxValue As Integer Dim RangValue As Integer Dim MidValue As Integer Dim Value As Integer Dim mChar As Byte Dim i As Integer Dim Index As Integer Dim EOF_State As Boolean Dim TopBit As Integer Dim One(256) As Integer Dim Zero(256) As Integer
ReDim outtext(500) OutPos = 0
OutBitCount = 0 OutByteBuf = 0 MinValue = 0
MaxValue = (2 ^ MaxBits) - 1 TopBit = 2 ^ (MaxBits - 1) InpPos = 0
Value = ReadBitsFromArray(listarr, InpPos, InBitPos, MaxBits) Index = -1
Zero(i) = 1 Next
Do
mChar = 0 For i = 0 To 7
Index = (1 * (2 ^ i)) - 1 + mChar RangValue = MaxValue - MinValue
MidValue = MinValue + RangValue * (Zero(Index) / (One(Index) + Zero(Index)))
If MidValue = MinValue Then MidValue = MidValue + 1 If MidValue = MaxValue - 1 Then MidValue = MidValue - 1 If Value >= MidValue Then
mChar = (2 * mChar) + 1 MinValue = MidValue One(Index) = One(Index) + 1 Else
mChar = 2 * mChar MaxValue = MidValue
Zero(Index) = Zero(Index) + 1 End If
Do While (MaxValue And TopBit) = (MinValue And TopBit) Or MinValue > MaxValue - 255
If InpPos <= UBound(listarr) Then
Value = (Value And (TopBit - 1)) * 2 + ReadBitsFromArray(listarr, InpPos, InBitPos, 1)
MaxValue = (MaxValue And (TopBit - 1)) * 2 + 1 MinValue = (MinValue And (TopBit - 1)) * 2
If MinValue >= MaxValue Then MaxValue = (2 ^ MaxBits) - 1 Else
EOF_State = True Exit Do
End If
Call AddmCharToArray(outtext, OutPos, mChar) Loop
ReDim Preserve outtext(OutPos - 1) End Sub
Private Sub AddBitsToouttext(ByRef Number As Integer) OutByteBuf = OutByteBuf * 2 + Number
OutBitCount = OutBitCount + 1 If OutBitCount = 8 Then
outtext(OutPos) = OutByteBuf OutBitCount = 0
If OutPos > UBound(outtext) Then ReDim Preserve outtext(OutPos + 500) End If
End If End Sub
Private Function ReadBitsFromArray(ByRef FromArray() As Byte, ByRef FromPos As Integer, ByRef FromBit As Integer, ByRef NumBits As Integer) As Integer
Dim i As Integer Dim Temp As Integer For i = 1 To NumBits
Temp = Temp * 2 + (-1 * ((FromArray(FromPos) And 2 ^ (7 - FromBit)) > 0)) FromBit = FromBit + 1
If FromBit = 8 Then
If FromPos + 1 > UBound(FromArray) Then Do While i < NumBits
Temp = Temp * 2 i = i + 1
Loop
FromPos = FromPos + 1 Exit For
End If
FromPos = FromPos + 1 FromBit = 0
End If Next
ReadBitsFromArray = Temp End Function
Private Sub AddmCharToArray(ByRef ToArray() As Byte, ByRef ToPos As Integer, ByRef mChar As Byte)
If ToPos > UBound(ToArray) Then ReDim Preserve ToArray(ToPos + 500) ToArray(ToPos) = mChar
ToPos = ToPos + 1 End Sub
CURRICULUM VITAE
Nama : Fiktaruddin
Tempat/Tanggal Lahir : Medan, 15 Maret 1991
Agama : Islam
Alamat Sekarang : Jl. Rajawali No.23F Medan Sunggal
Alamat Orang Tua : Jl. Medan-B.Aceh, Simp.Mulieng Aceh Utara
Telp/ Hp : 081376278380
Email : [email protected]
Riwayat Pendidikan
2006 – 2009 : SMA Al-Azhar Medan
2003 – 2006 : SMP Negeri 1 Simp.Mulieng, Syamtalira Aron 1997 – 2003 : SD Negeri 1 Simp.Mulieng, Syamtalira Aron
Pengalaman Organisasi dan Kegiatan Ilmiah
Anggota di bagian Biro Kesekretariatan Ikatan Mahasiswa S1 Ilmu Komputer
(IMILKOM), 2010-2012
Praktek Kerja Lapangan di Bank Sumut Cabang Pembantu Setia Budi Medan,
Juli-Agustus 2012