Pertama, kita mulai dengan Desain Form Menunya Sebagai berikut ;
Kemudian, Listing Programnya Sbb :
Public Class Form1
Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
Caesar_Chiper.Show()
End Sub
Private Sub GronsfeldChipeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfeldChipeToolStripMenuItem.Click
Gronsfeld_Chiper.Show()
End Sub
Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
Vernam_Chiper.Show()
End Sub
Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
Vigenere_Chiper.Show()
End Sub
Private Sub DESChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESChiperToolStripMenuItem.Click
DES_Chiper.Show()
End Sub
Private Sub RC4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RC4ToolStripMenuItem.Click
RC_4.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
-----------------------------------------------------------------------------------------------------------------------
Kemudian, bagian-bagian dari pada menu tersebut ;
1. Caesar Chiper
Tampilannya ;
Listing Program:
Public Class Caesar_Chiper
Private Sub enkripsi_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(Plainteks.Text)
x = Mid(Plainteks.Text, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
Chiperteks.Text = xkalimat
End Sub
Private Sub deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDeskripsi.Click
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiperteks.Text)
x = Mid(Chiperteks.Text, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
Plainteks.Text = xkalimat
End Sub
Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
Plainteks.Text = ""
Chiperteks.Text = ""
End Sub
Private Sub keluar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
Close()
End Sub
Private Sub Caesar_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
2. Gronsfield Chiper
Tampilannya
Listing Program ;
Public Class Gronsfeld_Chiper
Private Sub Gronsfeld_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Input.Text = ""
hasil.Text = ""
End Sub
Private Sub BtnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHitung.Click
Dim ind As Integer
Dim huruf, kalimat As String
Dim jumlah(25) As Integer
kalimat = (Input.Text).ToUpper
For x = 1 To Microsoft.VisualBasic.Len(kalimat)
huruf = kalimat.Substring(x - 1, 1)
If (huruf >= "A") And (huruf <= "Z") Then
ind = Asc(huruf) - 65
jumlah(ind) += 1
End If
Next
hasil.Text = ""
For i As Integer = 0 To 25
huruf = Chr(i + 65)
If jumlah(i) > 0 Then
hasil.Text = hasil.Text & huruf & " = " & jumlah(i) & vbCrLf
End If
Next
End Sub
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
Me.Close()
End Sub
End Class
3.Vernam Chiper
Tampilannya ;
Listing Program
Public Class Vernam_Chiper
Private Sub Vernam_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Plainteks.Text = ""
Kunci.Text = ""
Chiperteks.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 = 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
4. Vigenere Chiper
Tampilannya ;
Listing Program ;
Public Class Vigenere_Chiper
Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
chiperteks.Text = Enkripsi(plainteks.Text, kunci.Text)
End Sub
Function Enkripsi(ByVal Teks As String, ByVal Kunci As String) As String
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
jum = Len(Teks)
sPlain = ""
sKey = Kunci
sKata = Teks
For i = 1 To jum
If j = Len(sKey) Then
j = 1
Else
j = j + 1
End If
nKata = Asc(Mid(sKata, i, 1))
nKunci = Asc(Mid(sKey, j, 1))
nEnc = ((nKata + nKunci) Mod 256)
sPlain = sPlain & Chr((nEnc))
Next i
Enkripsi = sPlain
End Function
Private Sub BtnBersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBersih.Click
plainteks.Text = ""
chiperteks.Text = ""
kunci.Text = ""
End Sub
Private Sub Vigenere_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
5. DES Chiper
Tampilannya ;
Listing Program:
Public Class DES_Chiper
Private Sub Btn_enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_enkript.Click
Dim kunci As String, kunciChar As String, katabaru As String
Dim Pos As Integer
Dim i As Integer, Side1 As String, Side2 As String
Dim nEnc As Integer
Pos = 1
For i = 1 To Len(Plaintext.Text)
Plaintext.Text = Mid(Plaintext.Text, i, 1)
key.Text = Mid(key.Text, Pos, 1)
Chipertext.Text = Chipertext.Text & Chr(Asc(Of Char)() Xor Asc(key.Text))
If Pos = Len(kunci) Then Pos = 0
Pos = Pos + 1
Next i
If Len(Chipertext.Text) Mod 2 = 0 Then
Side1 = StrReverse(Left(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Side2 = StrReverse(Right(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Chipertext.Text = Side1 & Side2
End If
nEnc = Chipertext.Text
End Sub
End Class
6. RC4
Tampilannya ;
LISTING PROGRAM ;
Public Class RC4
Private Function Rc4(ByVal message As String, ByVal password As String) As String
Dim s = Enumerable.Range(0, 256).ToArray
Dim i, j As Integer
For i = 0 To s.Length - 1
j = (j + Asc(password(i Mod password.Length)) + s(i)) And 255
Dim temp = s(i)
s(i) = s(j)
s(j) = temp
Next
i = 0
j = 0
Dim sb As New System.Text.StringBuilder(message.Length)
For Each c As Char In message
i = (i + 1) And 255
j = (j + s(i)) And 255
Dim temp = s(i)
s(i) = s(j)
s(j) = temp
sb.Append(Chr(s((s(i) + s(j)) And 255) Xor Asc(c)))
Next
Return sb.ToString
End Function
Private Sub BtnEnkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkript.Click
Chipertext.Text = Rc4(Plaintext.Text, Key.Text)
End Sub
End Class
Belajar Pemrograman Selengkapnya ;
mesran.blogspot.com
Kemudian, Listing Programnya Sbb :
Public Class Form1
Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
Caesar_Chiper.Show()
End Sub
Private Sub GronsfeldChipeToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfeldChipeToolStripMenuItem.Click
Gronsfeld_Chiper.Show()
End Sub
Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
Vernam_Chiper.Show()
End Sub
Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
Vigenere_Chiper.Show()
End Sub
Private Sub DESChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESChiperToolStripMenuItem.Click
DES_Chiper.Show()
End Sub
Private Sub RC4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RC4ToolStripMenuItem.Click
RC_4.Show()
End Sub
Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
Me.Close()
End Sub
Private Sub FileToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileToolStripMenuItem.Click
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
-----------------------------------------------------------------------------------------------------------------------
Kemudian, bagian-bagian dari pada menu tersebut ;
1. Caesar Chiper
Tampilannya ;
Listing Program:
Public Class Caesar_Chiper
Private Sub enkripsi_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(Plainteks.Text)
x = Mid(Plainteks.Text, i, i)
x = Chr(Asc(x) + 3)
xkalimat = xkalimat + x
Next
Chiperteks.Text = xkalimat
End Sub
Private Sub deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDeskripsi.Click
Dim x As String = ""
Dim xkalimat As String = ""
For i = 1 To Len(Chiperteks.Text)
x = Mid(Chiperteks.Text, i, i)
x = Chr(Asc(x) - 3)
xkalimat = xkalimat + x
Next
Plainteks.Text = xkalimat
End Sub
Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
Plainteks.Text = ""
Chiperteks.Text = ""
End Sub
Private Sub keluar_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
Close()
End Sub
Private Sub Caesar_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
2. Gronsfield Chiper
Tampilannya
Listing Program ;
Public Class Gronsfeld_Chiper
Private Sub Gronsfeld_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Input.Text = ""
hasil.Text = ""
End Sub
Private Sub BtnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHitung.Click
Dim ind As Integer
Dim huruf, kalimat As String
Dim jumlah(25) As Integer
kalimat = (Input.Text).ToUpper
For x = 1 To Microsoft.VisualBasic.Len(kalimat)
huruf = kalimat.Substring(x - 1, 1)
If (huruf >= "A") And (huruf <= "Z") Then
ind = Asc(huruf) - 65
jumlah(ind) += 1
End If
Next
hasil.Text = ""
For i As Integer = 0 To 25
huruf = Chr(i + 65)
If jumlah(i) > 0 Then
hasil.Text = hasil.Text & huruf & " = " & jumlah(i) & vbCrLf
End If
Next
End Sub
Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
Me.Close()
End Sub
End Class
3.Vernam Chiper
Tampilannya ;
Listing Program
Public Class Vernam_Chiper
Private Sub Vernam_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Plainteks.Text = ""
Kunci.Text = ""
Chiperteks.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 = 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
4. Vigenere Chiper
Tampilannya ;
Listing Program ;
Public Class Vigenere_Chiper
Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
chiperteks.Text = Enkripsi(plainteks.Text, kunci.Text)
End Sub
Function Enkripsi(ByVal Teks As String, ByVal Kunci As String) As String
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
jum = Len(Teks)
sPlain = ""
sKey = Kunci
sKata = Teks
For i = 1 To jum
If j = Len(sKey) Then
j = 1
Else
j = j + 1
End If
nKata = Asc(Mid(sKata, i, 1))
nKunci = Asc(Mid(sKey, j, 1))
nEnc = ((nKata + nKunci) Mod 256)
sPlain = sPlain & Chr((nEnc))
Next i
Enkripsi = sPlain
End Function
Private Sub BtnBersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnBersih.Click
plainteks.Text = ""
chiperteks.Text = ""
kunci.Text = ""
End Sub
Private Sub Vigenere_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
5. DES Chiper
Tampilannya ;
Listing Program:
Public Class DES_Chiper
Private Sub Btn_enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_enkript.Click
Dim kunci As String, kunciChar As String, katabaru As String
Dim Pos As Integer
Dim i As Integer, Side1 As String, Side2 As String
Dim nEnc As Integer
Pos = 1
For i = 1 To Len(Plaintext.Text)
Plaintext.Text = Mid(Plaintext.Text, i, 1)
key.Text = Mid(key.Text, Pos, 1)
Chipertext.Text = Chipertext.Text & Chr(Asc(Of Char)() Xor Asc(key.Text))
If Pos = Len(kunci) Then Pos = 0
Pos = Pos + 1
Next i
If Len(Chipertext.Text) Mod 2 = 0 Then
Side1 = StrReverse(Left(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Side2 = StrReverse(Right(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Chipertext.Text = Side1 & Side2
End If
nEnc = Chipertext.Text
End Sub
End Class
6. RC4
Tampilannya ;
LISTING PROGRAM ;
Public Class RC4
Private Function Rc4(ByVal message As String, ByVal password As String) As String
Dim s = Enumerable.Range(0, 256).ToArray
Dim i, j As Integer
For i = 0 To s.Length - 1
j = (j + Asc(password(i Mod password.Length)) + s(i)) And 255
Dim temp = s(i)
s(i) = s(j)
s(j) = temp
Next
i = 0
j = 0
Dim sb As New System.Text.StringBuilder(message.Length)
For Each c As Char In message
i = (i + 1) And 255
j = (j + s(i)) And 255
Dim temp = s(i)
s(i) = s(j)
s(j) = temp
sb.Append(Chr(s((s(i) + s(j)) And 255) Xor Asc(c)))
Next
Return sb.ToString
End Function
Private Sub BtnEnkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkript.Click
Chipertext.Text = Rc4(Plaintext.Text, Key.Text)
End Sub
End Class
Belajar Pemrograman Selengkapnya ;
mesran.blogspot.com