Private Sub
autokey_chiper_Load(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
MyBase.Load
plaintext.Text = ""
kunci.Text =
""
chipertext.Text = ""
End Sub
Private Function
btn_AutokeyEncipher(ByVal strPlaintext As String, ByRef strKey As String) As String
Dim i As Long
Dim j As Long
Dim c1 As Integer
Dim c2 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
btnkeluar_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnkeluar.Click
Me.Close()
End Sub
Private Sub
btnhapus_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnhapus.Click
plaintext.Text = ""
kunci.Text =
""
chipertext.Text = ""
End Sub
Private Sub
btnenkripsi_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btn_Encipher.Click
chipertext.Text
= AutokeyEncipher(plaintext.Text, kunci.Text)
End Sub
End Class
6. kritografi Des chiper
desain program :
Gambar (6) Des chiper