You are on page 1of 7

Tampilan sebuah form dengan nama Form1, lalu tambahkan 4 buah GroupBox, 2

buah ComboBox, 2 buah Label, 2 buah TextBox, 3 buah Button dan 1 buah Timer,
dan tempatkan tools tersebut seperti gambar di bawah ini.

Lalu gantilah properti tools-tools atau komponen tersebut sesuai dengan tabel berikut.

Komponen Properties Nilai


Label1 Name labelpt
Text Plaintext
Font Microsoft Sans Serif, 8.25pt
Label2 Name labelcp
Text Ciphertext
Font Microsoft Sans Serif, 8.25pt
GroupBox1 Name GroupBoxKategori
Text Kategori
Font Microsoft Sans Serif, 8.25pt
GroupBox2 Name GroupBoxkalimat
Text Masukkan Kalimat
Font Microsoft Sans Serif, 8.25pt
GroupBox3 Name GroupBoxKunci
Text Kunci
Font Microsoft Sans Serif, 8.25pt
GroupBox4 Name GroupBoxaksi
Text Proses
Font Microsoft Sans Serif, 8.25pt
ComboBox1 Name ComboBoxkategori
Font Microsoft Sans Serif, 8.25pt
ComboBox2 Name ComboBoxkunci
Font Microsoft Sans Serif, 8.25pt
TextBox1 Name TextBoxpt
Font Microsoft Sans Serif, 8.25pt
Multiline True
ScrollBars Vertical
TextBox2 Name TextBoxcp
Font Microsoft Sans Serif, 8.25pt
Multiline True
ScrollBars Vertical
Button1 Name Buttonenkripsi
Text Enkripsi
Font Microsoft Sans Serif, 8.25pt
Cursor Hand
Button2 Name Buttondekripsi
Text Dekripsi
Font Microsoft Sans Serif, 8.25pt
Cursor Hand
Button3 Name Buttonhapus
Text Hapus
Font Microsoft Sans Serif, 8.25pt
Cursor Hand
Form1 Text PROGRAM KRIPTOGRAFI
MaximizeBox False
Size 1365, 740
StartPosition CenterScreen
Tampilan Awal Program

Tampilan Kategori

Dari tampilan ini terdapat GroupBoxKategori dan ComboBoxkategori


Klik Double pada ComboBoxkategori dan tulis coding berikut :
Private Sub ComboBoxkategori_SelectedIndexChanged(sender As Object, e
As EventArgs) Handles ComboBoxkategori.SelectedIndexChanged
If (ComboBoxkategori.SelectedItem = "Enkripsi") Then
ComboBoxkunci.Enabled = True
ComboBoxkunci.Focus()
TextBoxcp.Enabled = False
TextBoxpt.Enabled = True
Buttondekripsi.Enabled = False
Buttonenkripsi.Enabled = True
ElseIf (ComboBoxkategori.SelectedItem = "Dekripsi") Then
ComboBoxkunci.Enabled = True
ComboBoxkunci.Focus()
TextBoxpt.Enabled = False
TextBoxcp.Enabled = True
Buttonenkripsi.Enabled = False
Buttondekripsi.Enabled = True
End If
End Sub
Tampilan Kunci

Dari Tampilan di atas terdapat GroupBoxKunci dan ComboBoxkunci


Klik Double pada Form1 lalu tulis coding berikut :

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles


MyBase.Load
For i = 65 To 90
ComboBoxkunci.Items.Add(Chr(i))
Next
End Sub

Fungsi coding di atas yakni melakukan perulangan kode ASCII alphabet (A-Z)
yang digunakan untuk kunci dalam program kriptografi ini.

Tampilan Plaintext dan Ciphertext

Dari tampilan di atas terdapat GroupBoxkalimat, Labelpt untuk label Plaintext,


TextBoxpt untuk texbox Plaintext, Labelcp untuk label Cipher, dan TextBoxcp
untuk textbox Ciphertext.

Tampilan Proses
Button Enkripsi

Dalam tampilan di atas terdapat Buttonenkripsi


Klik Double pada Buttonenkripsi dan tuliskan coding berikut :

Private Sub Buttonenkripsi_Click(sender As Object, e As EventArgs) Handles


Buttonenkripsi.Click
Dim c, pi, ci, d As Integer
Dim hasil As String = ""
For j = 1 To Len(TextBoxpt.Text)
c = Asc(Mid(TextBoxpt.Text, j))
If ((c >= 65) And (c <= 90)) Then
pi = c - 65
ci = (pi + (ComboBoxkunci.SelectedIndex + 1)) Mod 26
d = ci + 65
hasil = hasil + Chr(d)
ElseIf ((c >= 97) And (c <= 122)) Then
pi = c - 97
ci = (pi + (ComboBoxkunci.SelectedIndex + 1)) Mod 26
d = ci + 97
hasil = hasil + Chr(d)
ElseIf (c = 32) Then
hasil = hasil + Chr(c)
ElseIf ((c >= 33) And (c <= 64)) Then
pi = c - 33
ci = (pi + (ComboBoxkunci.SelectedIndex + 1)) Mod 32
d = ci + 33
hasil = hasil + Chr(d)
Else
hasil = hasil + Chr(c)
End If
Next
TextBoxcp.Text = hasil
End Sub
Button Dekripsi

Dalam tampilan di atas terdapat Buttondekripsi


Klik Double pada Buttondekripsi dan tuliskan coding berikut :

Private Sub Buttondekripsi_Click(sender As Object, e As EventArgs) Handles


Buttondekripsi.Click
Dim c, pi, ci, d As Integer
Dim hasil As String = ""
For j = 1 To Len(TextBoxcp.Text)
c = Asc(Mid(TextBoxcp.Text, j))
If ((c >= 65) And (c <= 90)) Then
pi = c - 65
ci = (pi - (ComboBoxkunci.SelectedIndex - 25)) Mod 26
d = ci + 65
hasil = hasil + Chr(d)
ElseIf ((c >= 97) And (c <= 122)) Then
Button Hapus pi = c - 97
ci = (pi - (ComboBoxkunci.SelectedIndex - 25)) Mod 26
d = ci + 97
hasil = hasil + Chr(d)
ElseIf (c = 32) Then
hasil = hasil + Chr(c)
ElseIf ((c >= 33) And (c <= 64)) Then
pi = c - 33
ci = (pi - (ComboBoxkunci.SelectedIndex - 31)) Mod 32
d = ci + 33
hasil = hasil + Chr(d)
Else
hasil = hasil + Chr(c)
End If
Next
TextBoxpt.Text = hasil
End Sub

Dalam tampilan di atas terdapat Buttonhapus


Klik Double pada Buttonhapus dan tuliskan coding berikut :

Private Sub Buttonhapus_Click(sender As Object, e As EventArgs) Handles


Buttonhapus.Click
ComboBoxkategori.Focus()
ComboBoxkunci.Focus()
TextBoxpt.Clear()
TextBoxcp.Clear()
TextBoxpt.Enabled = True
TextBoxcp.Enabled = True
End Sub

You might also like