Form
dari beberapa Algoritma Kriptografi
Source
Code Caesar Chiper
Public Class caesar_chiper
Private Sub caesar_chiper_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintxt.Text = ""
chipertxt.Text = ""
End Sub
Private Sub Enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Enkripsi.Click
Dim
jumlah As Double
= Len(plaintxt.Text)
Dim x As String
Dim
x_kalimat As String
= ""
Dim i As Double
Dim bil
As Integer
For i =
1 To jumlah
x = Mid(plaintxt.Text, i, 1)
bil = Asc(x) + 3
x = Chr(bil)
x_kalimat = x_kalimat + x
Next i
chipertxt.Text = x_kalimat
End Sub
End Class
Form Gronsfeld Chiper
Source
Code Gronsfeld Chiper
Public Class gronsfeld_chiper
Private Sub Enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Enkripsi.Click
chipertxt.Text = enkrips(plaintxt.Text,
key.Text)
End Sub
Function
enkrips(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
enkrips = sPlain
End Function
End Class
Tampilan Program Gronsfeld Chiper
Source
Code Vernam Chiper (One Time Pad)
Public Class Vernam_Chiper
Private Sub Button1_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.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 = plaintxt.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
chipertxt.Text = sPlain
End Sub
Private Sub Vernam_Chiper_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plaintxt.Text = ""
chipertxt.Text = ""
kunci.Text = ""
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 plaintxt_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
plaintxt.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
Tampilan Program Vernam Chiper (One Time Pad)
Form Vigenere Chiper
Source
Code Vegenere Chiper
Public Class vigenere_chiper
Private Function VigenereEncipher(ByVal
strPlaintext As String,
ByRef strKey As
String) As String
Dim
strPlaintext2 As String
Dim
strKey2 As String
Dim
strCiphertext As String
Dim
strCiphertext2 As String
Dim i As Integer
Dim j As Integer
Dim c1 As Integer
Dim
nShift As Integer
Dim
pAlphabet As Integer
Dim
cAlphabet 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 key
sepanjang plaintext
If
(strKey2.Length < strPlaintext2.Length) Then
j = 0
For
i = 1 To strPlaintext2.Length
c1 = Asc(Mid(strPlaintext, i,
1))
strKey2 = strKey2 &
Mid(strKey2, j + 1, 1)
j = (j + 1) Mod strKey2.Length
Next
i
End If
'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 enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles enkripsi.Click
chipertxt.Text =
VigenereEncipher(plaintxt.Text, kunci.Text)
End Sub
End Class
Tampilan Program Vegenere Chiper
Source
Code DES Chiper (Data Encryption Standard)
Imports System.IO
Imports
System.Security.Cryptography
Imports
System.Text
Public Class des_chiper
Private Sub enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles enkripsi.Click
plaintxt.Text = "abcdef"
Dim enc
As Encoder =
System.Text.Encoding.Unicode.GetEncoder()
Dim
unicodeText As Byte()
unicodeText = DirectCast(Array.CreateInstance(GetType(Byte),
plaintxt.Text.Length * 2), Byte())
enc.GetBytes(plaintxt.Text.ToCharArray(), 0, plaintxt.Text.Length,
unicodeText, 0, True)
Dim
objmd5 As MD5 = New
MD5CryptoServiceProvider ' Untuk enkripsi MD5
'Dim objmd5
As MD5 = New SHA1CryptoServiceProvider() ' Untuk enkripsi SHA1
'Dim objmd5
As MD5 = New DESCryptoServiceProvider() ' Untuk enkripsi DES
'Dim objmd5
As MD5 = New RSACryptoServiceProvider ' Untuk enkripsi RSA
Dim
result As Byte()
= objmd5.ComputeHash(unicodeText)
Dim sb As StringBuilder = New
StringBuilder()
Dim i As Integer
For i =
0 To result.Length - 1
sb.Append(result(i).ToString("X2"))
Next
chipertxt.Text = sb.ToString()
'Anda dapat
mengganti "abcdef" dengan kata yang anda butuhkan, dan menggunakan
tipe enkripsi yang lain yang anda inginkan dengan mengaktifkan baris berikut :
'Dim objmd5
As MD5 = New MD5CryptoServiceProvider ' Untuk enkripsi MD5
'Dim objmd5
As MD5 = New SHA1CryptoServiceProvider() ' Untuk enkripsi SHA1
'Dim objmd5
As MD5 = New DESCryptoServiceProvider() ' Untuk enkripsi DES
'Dim objmd5
As MD5 = New RSACryptoServiceProvider ' Untuk enkripsi RSA
End Sub
End Class
รจSource
Code RC4 Chiper (Rivest Code)
Public Class rc4_chiper
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 enkripsi_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles enkripsi.Click
chipertxt.Text = Rc4(plaintxt.Text,
kunci.Text)
End Sub
End Class