mesran.punyablog
Selamat siang semua :),, kali ini saya akan mempostingkan materi pembahasan kriptografi.pada materi ini akan membahas kriptografi caesar,vernam,gronsfeld dan vigenore. langsung saja kita buat 5 form, dimana form1 akan kta jadikan menjadi form utama.
1. desain form1 seperti gambar di bawah ini :
isikan code berikut:
Public Class Form1
Private Sub CaesarToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
CaesarToolStripMenuItem.Click
Form2.Show()
End Sub
Private Sub VernamToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
VernamToolStripMenuItem.Click
Form3.Show()
End Sub
Private Sub GronsferToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
GronsferToolStripMenuItem.Click
Form4.Show()
End Sub
Private Sub VigenoreToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
VigenoreToolStripMenuItem.Click
Form5.Show()
End Sub
Private Sub ExitToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
ExitToolStripMenuItem.Click
End
End Sub
End Class
2. Pada form2 yaitu form caeasar buatlah 3label, 3 textbox, 3 button. lihat gambar di bawah ini:
Public Class Form2
Private Sub Btnenkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.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 As
System.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
Btnhapus_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles btnhapus.Click
plain.Text = ""
chiper.Text = ""
End Sub
Private Sub Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Me.Hide()
End Sub
End Class3. Desain form3 yaitu form vernam seperti di bawah ini :
isikan code berikut:
Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.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 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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Close()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
End Class
4. desain form 4 seperti gambar di bawah ini:
isi code berikut:
Public Class form4
Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.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 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 >= 48) And (tombol <= 57)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Close()
End Sub
End Class
5. desain form5 ,sebagai form vigenore seperti gambar di bawah ini:
isi code sebagai berikut:
Public Class form5
Private Sub form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.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 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 >= 32) And (tombol <= 47)) Or (tombol = 8)) Then
e.Handled = True
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
PLAINTEXT.Text = ""
KUNCI.Text = ""
CHIPPERTEXT.Text = ""
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Close()
End Sub
Private Sub Label4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label4.Click
End Sub
End Class
Sekian postingan dari saya :)
terima kasih





Tidak ada komentar:
Posting Komentar