Kriptografi
- Caesar
Public Class Form1
Private
Sub Form1_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Chiper.Text = ""
plainteks.Text = ""
End
Sub
Private
Sub Btnenkrip_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkrip.Click
Dim
x As String
Dim
bil As Integer
Chiper.Text = ""
For
i = 1 To Len(plainteks.Text)
x =
Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
bil = Asc(x)
bil = bil + 3 Mod 26
x = Chr(bil)
Chiper.Text =
Chiper.Text & x
Next
End
Sub
Private
Sub Btndes_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btndes.Click
Dim
x As String
Dim
bil As Integer
Chiper.Text = ""
For
i = 1 To Len(plainteks.Text)
x =
Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
bil = Asc(x)
bil = bil - 3 Mod 26
x = Chr(bil)
Chiper.Text =
Chiper.Text & x
Next
End
Sub
End Class
- Vernam
Public Class Form2
Private
Sub Form2_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
plain.Text = ""
kunci.Text = ""
Chiper.Text = ""
End
Sub
Private
Sub Btnenkrip_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkrip.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 = plain.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
Chiper.Text = sPlain
End
Sub
Private
Sub plain_KeyPress(ByVal
sender As Object,
ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles
plain.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 plain_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles plain.TextChanged
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 kunci_TextChanged(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles kunci.TextChanged
End
Sub
End Class
- Vigenere
Public Class Form3
Private
Sub Btnproses_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnproses.Click
chiper.Text =
enkripsi(Plain.Text, Kunci.Text)
End
Sub
Function
enkripsi(ByVal teks As
String, ByVal
kunci As String)
As String
Dim
a As Integer
Dim
b 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
a = 0
b = Len(teks)
sPlain = ""
sKey = kunci
sKata = teks
For
i = 1 To b
If
a = Len(sKey) Then
a = 1
Else
a = a + 1
End
If
nKata = Asc(Mid(sKata,
i, 1))
nKunci = Asc(Mid(sKey,
a, 1))
nEnc = ((nKata + nKunci)
Mod 256)
sPlain = sPlain &
Chr((nEnc))
Next
i
enkripsi = sPlain
End
Function
Private
Sub Btnhapus_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnhapus.Click
Plain.Text = ""
chiper.Text = ""
Kunci.Text = ""
End
Sub
Private
Sub Btnkeluar_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnkeluar.Click
Close()
End
Sub
End Class
- Grosfeld
Public Class Form4
Private
Sub Btnenkrip_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btnenkrip.Click
Dim
x As String
Dim
CI As Integer
Chiper.Text = ""
For
i = 1 To Len(plain.Text)
x =
Microsoft.VisualBasic.Mid(plain.Text, i, 1)
CI = Asc(x)
CI = (plain.Text +
Kunci.Text) Mod 26
x = Chr(CI)
Chiper.Text = Chiper.Text
& x
Next
Chiper.Text =
Enkripsi(plain.Text, Kunci.Text)
End
Sub
Private
Sub Btndes_Click(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles Btndes.Click
Dim
x As String
Dim
CI As Integer
Dim
KI As Integer
Dim
PI As Integer
Chiper.Text = ""
For
i = 1 To Len(plain.Text)
x =
Microsoft.VisualBasic.Mid(plain.Text, i, 1)
PI = Asc(x)
PI = (CI - KI) Mod 26
x = Chr(PI)
Chiper.Text = Chiper.Text & x
Next
End
Sub
Function
enkripsi(ByVal teks As
String, ByVal
kunci As String)
As String
Dim
a As Integer
Dim
b 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
a = 0
b = Len(teks)
sPlain = ""
sKey = kunci
sKata = teks
For
i = 1 To b
If
a = Len(sKey) Then
a = 1
Else
a = a + 1
End
If
nKata = Asc(Mid(sKata,
i, 1))
nKunci = Asc(Mid(sKey,
a, 1))
nEnc = ((nKata + nKunci)
Mod 26)
sPlain = sPlain &
Chr((nEnc))
Next
i
enkripsi = sPlain
End
Function
Private
Sub Form4_Load(ByVal
sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Chiper.Text = ""
plain.Text = ""
Kunci.Text = ""
End
Sub
End Class




0 komentar:
Posting Komentar