Tahap
Pembuatan Kriptografi pada VB 2008
Blog
sayakali ini akan memposting kriptografi pada program
Visual Basic 2008. 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.
Langkah pertama yang kita lakukan adalah Buatlah 5 Form pada VB 2008.
Ø Pada Form 1 kita buat itu menjadi induknya, seperti
berikut ini :
Untuk membuat “File” dan “Profil” tersebut
gunakanlah Menustrip yang terdapat pada toolbox.
Setelah itu masukkan code
berikut ini ke form 1 :
Public Class Form1
Private Sub caesarToolStripMenuItem_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles GronsferToolStripMenuItem.Click
Form2.Show()
End Sub
Private Sub vernamToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles CaesarToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub GronseldToolStripMenuItem_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles VigenoreToolStripMenuItem.Click
Form4.Show()
End Sub
Private Sub VigenoreToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles VernamToolStripMenuItem.Click
Form5.Show()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub profilToolStripMenuItem_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles AboutToolStripMenuItem.Click
MsgBox("Nama : Apryanti
savitri, Email : apryantisavitri08@gamil.com
apryantisavitri08.blogspot.com”)
End Sub
End Class
Ø
Nah , pada selanjutnya kita akan membuat isi
process dari Menu”File” tersebut.
Pada Form2
kita rancang untuk Kriptografi Caesar, Buatlah 2 label, 2 textbox, dan 1 button yang masing-Masing sebagai Berikut :
Lalu Masukkan Code berikut
ini di Form2 :
Public Class Form2
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
End Class
Ø Sekarang
pada form3 kita gunakan untuk Kriptografi Vernam, caranya pada
Form 3, Buatlah 3 label, 3 textbox, dan 1 button yang masing-Masing sebagai Berikut :
Lalu masukkan lah code ini
kedalamnya :
Public Class Form3
Private Sub Form3_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintext.Text = ""
kunci.Text = ""
chipertext.Text = ""
End Sub
Private Sub btnenkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles btnenkripsi.Click
plaintext.Text = ""
kunci.Text = ""
chipertext.Text = ""
End Sub
Private Sub enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.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
chipertext.Text = splain
End Sub
Private Sub plaintext_KeyPress(ByVal
sender As Object,
ByVal e As
System.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 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
Ø Pada
Form4 kita gunakan untuk Kriptografi Gronseld, langkah-langkahnya:
Pada Form 4, Buatlah 3 label, 3 textbox, dan 1 button yang masing-Masing sebagai Berikut
:
Lalu Masukkan Code Berikut
ini di 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)) - 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
End Class
Ø Terakhir
pada Form5 kita gunakan untuk kriptografi Vigenore, cara buatnya:
Lalu masukkan Code berikut
ini di dalam form5 :
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 >= 32) And (tombol <= 47)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
End Class
Sekarang Compile lah aplikasi itu dengan
menekan F5
Maka Hasil dari yang kita
buat tersebut sebagai berikut ini :
Sekian postingan saya kali
ini,, Moga bermanfaaaaaaaaaaaaaaaaattt !!!! ^_^