LISTING PROGRAM
1. Form Home.vb
Public Class Form1 Private Sub Label1_ClickByVal sender As System.Object, ByVal e As
System.EventArgs End Sub
Private Sub AlgoritmaToolStripMenuItem_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles
AlgoritmaToolStripMenuItem.Click Form2.Show
End Sub Private Sub MenuToolStripMenuItem_ClickByVal sender As System.Object,
ByVal e As System.EventArgs Handles MenuToolStripMenuItem.Click End Sub
Private Sub EnkripsiKompresiToolStripMenuItem_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles
EnkripsiKompresiToolStripMenuItem.Click Form3.Show
End Sub Private Sub DekripsiDekompresiToolStripMenuItem_ClickByVal sender As
System.Object, ByVal e As System.EventArgs Handles DekripsiDekompresiToolStripMenuItem.Click
Form4.Show End Sub
Private Sub TentangToolStripMenuItem_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles
TentangToolStripMenuItem.Click Form5.Show
End Sub Private Sub BerandaToolStripMenuItem_ClickByVal sender As
System.Object, ByVal e As System.EventArgs End Sub
Private Sub Form1_LoadByVal sender As System.Object, ByVal e As System.EventArgs Handles MyBase.Load
End Sub Private Sub KompresiEnkripsiToolStripMenuItem_ClickByVal sender As
System.Object, ByVal e As System.EventArgs Handles KompresiEnkripsiToolStripMenuItem.Click
Form6.Show End Sub
Universitas Sumatera Utara
Private Sub DekripsiDekompresiToolStripMenuItem1_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles
DekripsiDekompresiToolStripMenuItem1.Click Form7.Show
End Sub End Class
2. Form Enkripsi-Kompresi .vb
Imports System.IO Imports Microsoft.Office.Interop.Word
Public Class Form3 Dim strFileName As String
Dim cipher As String = Dim alpabet As Char = New Char94 {}
Dim ab As Integer = 0 Dim plain As String =
Dim waktu_proses As New Stopwatch Public Const EOF As Char = ChrW127
Public Const ESCAPE As Char = ChrW165 Private Function cekKunciByVal huruf As Char As Boolean
For i As Integer = 0 To ab - 1 If alpabeti = huruf Then
Return False End If
Next alpabetab = huruf
ab += 1 Return True
End Function Private Sub putarKunci1ByVal matrix As Char,, ByVal huruf As Char
Dim limit As Boolean = False Dim temp As Char = c
For i As Integer = 0 To 18 For j As Integer = 0 To 4
If matrixi, j = huruf Then If j = 4 AndAlso i = 18 Then
temp = matrixi, j matrixi, j = matrix0, j
matrix0, j = matrix0, 0 matrix0, 0 = matrixi, 0
matrixi, 0 = temp limit = True
Exit For ElseIf i = 18 Then
temp = matrixi, j
Universitas Sumatera Utara
matrixi, j = matrix0, j matrix0, j = matrix0, j + 1
matrix0, j + 1 = matrixi, j + 1 matrixi, j + 1 = temp
limit = True Exit For
ElseIf j = 4 Then temp = matrixi, j
matrixi, j = matrixi + 1, j matrixi + 1, j = matrixi + 1, 0
matrixi + 1, 0 = matrixi, 0 matrixi, 0 = temp
limit = True Exit For
Else temp = matrixi, j
matrixi, j = matrixi + 1, j matrixi + 1, j = matrixi + 1, j + 1
matrixi + 1, j + 1 = matrixi, j + 1 matrixi, j + 1 = temp
limit = True Exit For
End If End If
Next If limit Then
Exit For End If
Next End Sub
Private Sub putarKunci2ByVal matrix As Char,, ByVal huruf As Char Dim limit As Boolean = False
Dim temp As Char = c For i As Integer = 0 To 18
For j As Integer = 0 To 4 If matrixi, j = huruf Then
If i = 18 AndAlso j = 4 Then temp = matrixi, j
matrixi, j = matrixi, 0 matrixi, 0 = matrix0, 0
matrix0, 0 = matrix0, j matrix0, j = temp
limit = True Exit For
ElseIf i = 18 Then temp = matrixi, j
matrixi, j = matrixi, j + 1 matrixi, j + 1 = matrix0, j + 1
matrix0, j + 1 = matrix0, j matrix0, j = temp
limit = True Exit For
Universitas Sumatera Utara
Universitas Sumatera Utara
ElseIf j = 4 Then temp = matrixi, j
matrixi, j = matrixi, 0 matrixi, 0 = matrixi + 1, 0
matrixi + 1, 0 = matrixi + 1, j matrixi + 1, j = temp
limit = True Exit For
Else temp = matrixi, j
matrixi, j = matrixi, j + 1 matrixi, j + 1 = matrixi + 1, j + 1
matrixi + 1, j + 1 = matrixi + 1, j matrixi + 1, j = temp
limit = True Exit For
End If End If
Next If limit Then
Exit For End If
Next End Sub
Private Sub enkripsiByVal bigram As String, ByVal Matrik As Char, Dim limit As Boolean = False
Dim bigramx As Integer = New Integer1 {} Dim bigramy As Integer = New Integer1 {}
For x As Integer = 0 To 1 For i As Integer = 0 To 18
For j As Integer = 0 To 4 If bigramx = Matriki, j Then
bigramxx = i bigramyx = j
limit = True If limit = True AndAlso x = 2 Then
Exit For End If
End If Next
If limit = True AndAlso x = 2 Then Exit For
End If Next
Next If bigramx0 = bigramx1 Then
If bigramy0 = 4 Then cipher += Matrikbigramx0, 0.ToString +
Matrikbigramx1, bigramy1 + 1.ToString ElseIf bigramy1 = 4 Then
Universitas Sumatera Utara
Universitas Sumatera Utara
cipher += Matrikbigramx0, bigramy0 + 1.ToString + Matrikbigramx1, 0.ToString
Else cipher += Matrikbigramx0, bigramy0 + 1.ToString
+ Matrikbigramx1, bigramy1 + 1.ToString End If
ElseIf bigramy0 = bigramy1 Then If bigramx0 = 18 Then
cipher += Matrik0, bigramy0.ToString + Matrikbigramx1 + 1, bigramy1.ToString
ElseIf bigramx1 = 18 Then cipher += Matrikbigramx0 + 1, bigramy0.ToString
+ Matrik0, bigramy1.ToString Else
cipher += Matrikbigramx0 + 1, bigramy0.ToString + Matrikbigramx1 + 1, bigramy1.ToString
End If Else
cipher += Matrikbigramx0, bigramy1.ToString + Matrikbigramx1, bigramy0.ToString
End If TextBox3.Text = cipher
End Sub Private Sub cari_ClickByVal sender As System.Object, ByVal e As
System.EventArgs Handles cari.Click Dim AmbilFile As New OpenFileDialog
Dim objFSO As New Scripting.FileSystemObject Dim objFile As Scripting.File
objFSO = New Scripting.FileSystemObject AmbilFile.CheckFileExists = True
AmbilFile.CheckPathExists = True AmbilFile.DefaultExt = txt
AmbilFile.Filter = Documen.doc|.doc|document.docx|.docx|TXT File .txt|.txt|All
Files .|. AmbilFile.Multiselect = False
AmbilFile.ShowDialog strFileName = AmbilFile.FileName
Textcari.Text = strFileName Dim app As Application = New Application
Dim doc As Document = app.Documents.AddstrFileName Dim co As Integer = doc.Characters.Count
For i As Integer = 1 To co - 1 Dim tex As String = doc.Charactersi.Text
TextBox1.Text += tex Next
TextBox9.Text = TextBox1.TextLength objFile = objFSO.GetFilestrFileName
TextBox7.Text = objFile.Size bytes End Sub
Universitas Sumatera Utara
Universitas Sumatera Utara
Private Sub Button2_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles Button2.Click
Dim kunci As String = TextBox2.Text Dim PKunci As Integer = kunci.Length
Dim a As Integer = 0, asci As Integer = 32 Dim Matrik As Char, = New Char18, 4 {}
waktu_proses.Start For i As Integer = 0 To 18
For j As Integer = 0 To 4 If a PKunci Then
If cekKuncikuncia = True Then Matriki, j = kuncia
Else j -= 1
End If a += 1
Else If cekKunciChrWasci = True Then
Matriki, j = ChrWasci Else
j -= 1 End If
asci += 1 End If
Next Next
Dim plain As String = TextBox1.Text Dim bigram As String =
If plain.Length Mod 2 0 Then plain += x
End If Dim x As Integer = 0
bigram = plain.Substringx, 2 x += 2
enkripsibigram, Matrik For i As Integer = 0 To plain.Length - 3
If i Mod 2 = 0 Then putarKunci1Matrik, plaini
Else putarKunci2Matrik, plaini
bigram = plain.Substringx, 2 x += 2
enkripsibigram, Matrik End If
Next waktu_proses.Stop
TextBox6.Text = waktu_proses.Elapsed.TotalSeconds.ToString waktu_proses.Reset
End Sub Private Sub hapus_ClickByVal sender As System.Object, ByVal e As
System.EventArgs Handles hapus.Click TextBox1.Text =
Universitas Sumatera Utara
Universitas Sumatera Utara
Textcari.Text = TextBox2.Text =
TextBox3.Text = TextBox4.Text =
MsgBoxData telah dihapus, MsgBoxStyle.Exclamation, Perhatian
End Sub Private Sub Button3_ClickByVal sender As System.Object, ByVal e As
System.EventArgs Handles Button3.Click Dim i As Integer = FreeFile
FileOpeni, D:\KULIAH\hasil.txt, OpenMode.Output PrintLinei, TextBox3.Text
FileClosei MsgBoxData telah disimpan, MsgBoxStyle.Information,
Perhatian End Sub
Private Sub Button5_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles Button5.Click
Dim i As Integer = FreeFile FileOpeni, D:\KULIAH\finish.txt, OpenMode.Output
PrintLinei, TextBox4.Text FileClosei
MsgBoxData telah disimpan, MsgBoxStyle.Information, Perhatian
End Sub
Public Shared Function RunLengthEncodeByVal s As String As String Dim srle As String = String.Empty
Dim ccnt As Integer = 1 char counter
For i As Integer = 0 To s.Length - 2 If si si + 1 OrElse i = s.Length - 2 Then
..a break in character repetition or the end of the
string If si = si + 1 AndAlso i = s.Length - 2 Then
end of string condition ccnt += 1
End If If ccnt = 1 Then
srle += If1234567890.Containssi.ToString,
+ ESCAPE, + si Else
escape digits srle += ccnt.ToString +
If1234567890.Containssi.ToString, + ESCAPE, + si End If
escape digits If si si + 1 AndAlso i = s.Length - 2 Then
end of string condition srle += If1234567890.Containssi +
1.ToString, 1 + ESCAPE, + si + 1
Universitas Sumatera Utara
Universitas Sumatera Utara
End If reset char repetition counter
ccnt = 1 Else
ccnt += 1 End If
Next Return srle
End Function
Private Sub Button4_ClickByVal sender As System.Object, ByVal e As System.EventArgs Handles Button4.Click
waktu_proses.Start TextBox4.Text = RunLengthEncodeTextBox3.Text
TextBox10.Text = TextBox4.Text.Count waktu_proses.Stop
TextBox5.Text = waktu_proses.Elapsed.TotalSeconds.ToString waktu_proses.Reset
End Sub End Class
3. Form Dekompresi-Dekripsi .vb