Pemograman Kriptografi terdiri dari 2, yaitu :
1. Kriptografi Caesar
2. Kriptografi Verman
Berikut ini merupakan contoh pemograman Kriptografi yang didalamnya terdapat juga penggunaan menuStrip.
1. Buka menu VisualBaasic, kemudian pilih New>>Project>>Ok
2. Dalam project tersebut buatlah Form1, Form2, dan Form3
seperti berikut:
Listing Program untuk Form1
Public
Class Form1
Private Sub enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles enkripsi.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) + (5 - 101 / 56))
xkalimat = xkalimat + x
Next
chiper.Text = xkalimat
End Sub
Private Sub chiper_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles chiper.TextChanged
End Sub
Private Sub dekripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles dekripsi.Click
Dim x As String = ""
Dim
xkalimat As String
= ""
For i =
1 To Len(chiper.Text)
x = Mid(chiper.Text, i, i)
x = Chr(Asc(x) - (5 - 101 / 56))
xkalimat = xkalimat + x
Next
chiper.Text = xkalimat
End Sub
End
Class
Listing Program untuk Form2
Public
Class Form2
Private Sub Form1ToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
Form1ToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub KriftografiCaesarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KriftografiCaesarToolStripMenuItem.Click
Form1.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
KeluarToolStripMenuItem.Click
End
End Sub
End Class
Listing Program untuk Form3
Public Class
Form3
Private Sub Form3_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plainteks.Text = ""
kunci.Text = ""
chiperteks.Text = ""
End Sub
Private Sub benkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles benkripsi.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 = plainteks.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
chiperteks.Text = splain
End Sub
Private Sub plainteks_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
plainteks.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 As
System.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
End Class
Sebelum
menjalankan program tersebut StarUp Formnya diubah ter lebih dahulu, karena
Form yang Akan starup adalah Form2, maka caranya adalah Buka PROJECTà
PROPERTIES. Pada bagian StarUp Form diubah menjadi Form2. Maka tampilan yang
akan muncul saat di jalan kan seperti berikut:
Saat dipilih
File -->> Kriptogafi Verman, maka akan muncul tampilan berikut:
Saat dipilih
File -->> Kriptogafi Caesar, maka akan muncul tampilan berikut: