salam anak bangsa-, pada hari ini saya akan mempostingkan aplikasi membuat “Kriptografi” dengan Visual Basic 2008. Sebelumnya saya akan menjelaskan sedikit apa itu Kriptografi. Kriptografi adalah penambahan beberapa huruf, angka dan simbol-simbol tertentu kedalam sebuah text, dengan tujuan orang lain tidak dapat membaca pesan yang anda kirimkan ke sahabat anda, dimana sahabat anda juga mengerti pesan tersebut.
Langsung saja, saya akan membuat 4 Kriptografi yaitu : Kriptografi Caesar, Kriptografi Vernam, Kriptografi Gronsfeld, dan Kroptografi Vigenore.
Pertama Buatlah 5 Form pada VB 2008.
(+)Pada Form 1 kita buat itu menjadi induknya, seperti berikut ini
Untuk membuat “File” dan “About” tersebut gunakanlah Menustrip yang terdapat pada toolbox.
Public Class Form1
Private Sub GronsferToolStripMenuItem_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles GronsferToolStripMenuItem.Click
Form2.Show()
End Sub
Private Sub CaesarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles CaesarToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub VigenoreToolStripMenuItem_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles VigenoreToolStripMenuItem.Click
Form4.Show()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles AboutToolStripMenuItem.Click
End Sub
Private Sub VernamToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles VernamToolStripMenuItem.Click
Form5.Show()
End Sub
End Class
(+)Pada Form 2, Buatlah 3 label, 3 textbox, dan 3 button yang masing-Masing sebagai Berikut :
Lalu Masukkan Code Berikut ini di Form2 :
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
plaintext.Text = ""
kunci.Text = ""
chippertext.Text = ""
End Sub
Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles enkripsi.Click
Dim J As Integer
Dim jum As Integer
Dim skey As String
Dim nkata As Integer
Dim nkunci As Integer
Dim skata As String
Dim splain As String = ""
Dim nenc As Integer
J = 0
skata = plaintext.Text
jum = Len(skata)
skey = kunci.Text
For i = 1 To jum
If J = Len(skey) Then
J = 1
Else
J = J + 1
End If
nkata = Asc(Mid(skata, i, 1)) - 26
nkunci = Asc(Mid(skey, J, 1)) - 10
nenc = ((nkata + nkunci) Mod 26)
splain = splain & Chr((nenc) + 65)
Next i
chippertext.Text = splain
End Sub
Private Sub plaintext_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles plaintext.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub kunci_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles kunci.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 48) And (tombol <= 57)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
plaintext.Text = ""
kunci.Text = ""
chippertext.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
End Class
(+)Pada Form3, Buatlah desain 2 label, 2 textbox, dan 4 button yang masing-Masing sebagai Berikut :
Lalu Masukkan Code berikut ini di Form3 :
Public Class Form3
Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Btnenkripsi.Click
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(plain.Text)
x = Mid(plain.Text, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
chiper.Text = xkalimat
End Sub
Private Sub Btndeskripsi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Btndeskripsi.Click
Dim x As String = ""
Dim xenkripsi As String = ""
For i = 1 To Len(chiper.Text)
x = Mid(chiper.Text, i, i)
x = Chr(Asc(x) - 3)
xenkripsi = xenkripsi + x
Next
chiper.Text = xenkripsi
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
plain.Text = ""
chiper.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
End Class
(+)Pada Form4 buatlah desain sepeti bentuk form2, Hasilnya seperti berikut :
Lalu masukkan Code berikut ini di dalam form4 :
Public Class Form4
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
plaintext.Text = ""
kunci.Text = ""
chippertext.Text = ""
End Sub
Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles enkripsi.Click
Dim J As Integer
Dim jum As Integer
Dim skey As String
Dim nkata As Integer
Dim nkunci As Integer
Dim skata As String
Dim splain As String = ""
Dim nenc As Integer
J = 0
skata = plaintext.Text
jum = Len(skata)
skey = kunci.Text
For i = 1 To jum
If J = Len(skey) Then
J = 1
Else
J = J + 1
End If
nkata = Asc(Mid(skata, i, 1)) - 65
nkunci = Asc(Mid(skey, J, 1)) - 65
nenc = ((nkata + nkunci) Mod 26)
splain = splain & Chr((nenc) + 65)
Next i
chippertext.Text = splain
End Sub
Private Sub plaintext_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles plaintext.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub kunci_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles kunci.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 32) And (tombol <= 47)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
plaintext.Text = ""
kunci.Text = ""
chippertext.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
End Class
Pada Form5, buat juga desain seperti 2 dan 4, dan hasilnya seperti ini :
Lalu masukkan lah code ini kedalamnya :
Public Class Form5
Private Sub Form5_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
plaintext.Text = ""
kunci.Text = ""
chippertext.Text = ""
End Sub
Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles enkripsi.Click
Dim J As Integer
Dim jum As Integer
Dim skey As String
Dim nkata As Integer
Dim nkunci As Integer
Dim skata As String
Dim splain As String = ""
Dim nenc As Integer
J = 0
skata = plaintext.Text
jum = Len(skata)
skey = kunci.Text
For i = 1 To jum
If J = Len(skey) Then
J = 1
Else
J = J + 1
End If
nkata = Asc(Mid(skata, i, 1)) - 65
nkunci = Asc(Mid(skey, J, 1)) - 65
nenc = ((nkata + nkunci) Mod 26)
splain = splain & Chr((nenc) + 65)
Next i
chippertext.Text = splain
End Sub
Private Sub plaintext_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles plaintext.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub kunci_KeyPress(ByVal sender As Object, ByVal e AsSystem.Windows.Forms.KeyPressEventArgs) Handles kunci.KeyPress
e.KeyChar = UCase(e.KeyChar)
Dim tombol As Integer = Asc(e.KeyChar)
If Not (((tombol >= 65) And (tombol <= 90)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button1.Click
chippertext.Text = ""
kunci.Text = ""
plaintext.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles Button2.Click
Me.Hide()
End Sub
End Class
Nah, Akhirnya selesai juga. Sekarang Compile lah aplikasi itu dengan menekan F5
Maka Hasil dari yang kita buat tersebut sebagai berikut ini :