Berikut
Listing Programnya:
Public Class Form1
Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
CaesarChiperToolStripMenuItem.Click
Form2.MdiParent = Me
Form2.Show()
End Sub
Private Sub GronsfieldChiperToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
GronsfieldChiperToolStripMenuItem.Click
Form3.MdiParent = Me
Form3.Show()
End Sub
Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
VernamChiperToolStripMenuItem.Click
Form4.MdiParent = Me
Form4.Show()
End Sub
Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
VigenereChiperToolStripMenuItem.Click
Form5.MdiParent = Me
Form5.Show()
End Sub
Private Sub DesChiperToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
DesChiperToolStripMenuItem.Click
Form6.MdiParent = Me
Form6.Show()
End Sub
Private Sub RC4ToolStripMenuItem_Click(ByVal sender As
System.Object, ByVal e As
System.EventArgs) Handles
RC4ToolStripMenuItem.Click
Form7.MdiParent = Me
Form7.Show()
End Sub
End Class
Berikut isi daripada menunya:
1.Caesar Chiper
Listing programnya:
Public Class Form2
Private Sub Form2_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintext.Text = ""
chipertext.Text = ""
End Sub
Private Sub Btnenkript_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkript.Click
Dim
jumlah As Double
= Len(plaintext.Text)
Dim x As String
Dim
xkalimat As String
= ""
Dim bil
As Integer
For i =
1 To jumlah
x = Mid(plaintext.Text, i, 1)
bil = Asc(x) + 3
x = Chr(bil)
xkalimat = xkalimat + x
Next i
chipertext.Text = xkalimat
End Sub
End Class
2.Gronsfield
Chiper
Berikut Listing Programnya :
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 Btnenkript_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkript.Click
Dim J As Integer
Dim Jum
As Integer
Dim
sKey As String
Dim
nKata As Integer
Dim
nKunci As String
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))
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
3.Vernam
Chiper
Berikut Listing Programnya :
Public Class Form4
Private Sub Form4_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintext.Text = ""
chipertext.Text = ""
kunci.Text = ""
End Sub
Private Sub Btnenkript_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkript.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
4.Vigenere
Chiper
Listing Programnya:
Public Class Form5
Private Sub Form5_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintext.Text = ""
kunci.Text = ""
chipertext.Text = ""
End Sub
Private Sub Btnenkript_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkript.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)) + 0
nKunci = Asc(Mid(sKey, J, 1)) + 0
nEnc = ((nKata + nKunci) Mod 256)
sPlain = sPlain & Chr((nEnc))
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
5.RC4
Listing Programnya :
Private Sub RC4_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load
plaintext.Text
= ""
kunci.Text
= ""
chipertext.Text
= ""
End Sub
Private Function AutokeyEncipher(ByVal strPlaintext As String,ByRef strKey As String) As String
Dim i As Long
Dim j As Long
Dim c1 As Integer
Dim strPlaintext2 As String
Dim strKey2 As String
Dim strCiphertext As String
Dim strCiphertext2 As String
Dim diffKeyLen As Integer
Dim pAlphabet As Integer
Dim cAlphabet As Integer
Dim nShift As Integer
'1.
Hilangkan semua karakter yang bukan alfabet dari strPlaintext
'
dan simpan sebagai strPlaintext2
strPlaintext2
= ""
For i
= 1 To strPlaintext.Length
c1
= Asc(Mid(strPlaintext, i, 1))
If (c1
>= 65 And c1 <= 90) Then
strPlaintext2
= strPlaintext2 & Chr(c1)
End If
Next i
'2.
Hilangkan semua karakter yang bukan alfabet dari strKey
'
dan simpan sebagai strKey2
strKey2
= ""
For i
= 1 To strKey.Length
c1
= Asc(Mid(strKey, i, 1))
If (c1
>= 65 And c1 <= 90) Then
strKey2
= strKey2 & Chr(c1)
End If
Next i
'3.
Susun kunci baru strKey2 berdasarkan kunci awal strKey kemudian
'
ditambah plaintext
'perbedaan
antara panjang plaintext dan kunci
diffKeyLen
= strPlaintext2.Length - strKey2.Length
For i
= 1 To diffKeyLen
'c1
= Asc(Mid(strPlaintext2, i, 1))
strKey2
= strKey2 & Mid(strPlaintext2, i, 1)
Next i
'4.
Geser masing-masing huruf pada plaintext
'
dengan huruf yang terkait pada key
strCiphertext
= ""
For i
= 1 To strPlaintext2.Length
c1
= Asc(Mid$(strPlaintext2, i, 1))
nShift
= Asc(Mid$(strKey2, i, 1)) - 65
If ((c1
>= 65) And (c1 <= 90)) Then
pAlphabet
= c1 - 65 ' get the alphabet sequence
cAlphabet
= (pAlphabet + nShift) Mod 26 ' shifted alphabet
c1
= cAlphabet + 65 ' get character in 65 ... 90
End If
strCiphertext
= strCiphertext & Chr(c1)
Next i
'5.
Susun strCiphertext sesuai dengan urutan strPlaintext
strCiphertext2
= ""
strKey
= ""
j
= 1
For i
= 1 To strPlaintext.Length
c1
= Asc(Mid$(strPlaintext, i, 1))
If ((c1
>= 65) And (c1 <= 90)) Then
strCiphertext2
= strCiphertext2 & Mid(strCiphertext, j, 1)
strKey
= strKey & Mid(strKey2, j, 1)
j
= j + 1
Else
strCiphertext2
= strCiphertext2 & Chr(c1)
strKey
= strKey & " "
End If
Next i
Return strCiphertext2
End Function
Private Sub hapus_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles hapus.Click
plaintext.Text
= ""
kunci.Text
= ""
chipertext.Text
= ""
End Sub
Private Sub keluar_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles keluar.Click
Me.Close()
End Sub
Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles enkripsi.Click
chipertext.Text
= AutokeyEncipher(plaintext.Text, kunci.Text)
End Sub
Private Sub deskripsi_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles deskripsi.Click
End Sub
End Class
Public Class Form1
Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) HandlesCaesarChiperToolStripMenuItem.Click
Caesar.Show()
End Sub
Private Sub VernamChiper_Click(ByVal sender As System.Object, ByVale As System.EventArgs) Handles VernamChiper.Click
Vernam.Show()
End Sub
Private Sub VigenereChiper_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles VigenereChiper.Click
Vigenere.Show()
End Sub
Private Sub DesChiper_Click(ByVal sender As System.Object, ByVal eAs System.EventArgs) Handles DesChiperr.Click
RC4.Show()
End Sub
Private Sub GronsfeldChiper_Click(ByVal sender As System.Object,ByVal e As System.EventArgs) Handles GronsfeldChiper.Click
DesChiper.Show()
End Sub
Private Sub KeluarToolStripMenuItem1_Click(ByVal sender AsSystem.Object, ByVal e As System.EventArgs) HandlesKeluarToolStripMenuItem1.Click
Dim i As MsgBoxResult
i
= MsgBox("Apa anda ingin keluar?", MsgBoxStyle.Information +
MsgBoxStyle.YesNo, "Perhatian")
If i
= MsgBoxResult.Yes Then
Close()
End If
End Sub
End Class
Demikian pembelajaran kriptografi ini
Semoga bermanfaat :)
0 komentar:
Posting Komentar