Minggu, 30 Juni 2013

Kriptografi

  •  
  • Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            plainteks.Text = ""
            chiperteks.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(plainteks.Text)
            Dim x As String
            Dim xkalimat As String = ""
            Dim i As Double
            Dim bil As Integer
            For i = 1 To jumlah
                x = Mid(plainteks.Text, i, 1)
                bil = Asc(x) + 3
                x = Chr(bil)
                xkalimat = xkalimat + x
            Next i
            chiperteks.Text = xkalimat
        End Sub
        Private Sub Btnerase_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnerase.Click
            chiperteks.Text = ""
            plainteks.Text = ""
        End Sub
    End Class
     
  •  Caesar

Public Class Form2

    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
        Chiperteks.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)
            Chiperteks.Text = Chiperteks.Text & x
        Next
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        chiperteks.Text = ""
        plainteks.Text = ""

    End Sub

    Private Sub Btndeskrip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndeskrip.Click
        Dim x As String
        Dim bil As Integer
        chiperteks.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)
            chiperteks.Text = chiperteks.Text & x
        Next

    End Sub
End Class


  • Vernam
  • Public Class Form3

        Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            plainteks.Text = ""
            kunci.Text = ""
            chiperteks.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 = 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

  • Vigenere
Public Class Form4

    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 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
        plainteks.Text = ""
        chiperteks.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


  • Gronsfeld
  • Public Class Form5
  •  Private Sub Btnenkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkript.Click
            Dim x As String
            Dim CI As Integer
            chiperteks.Text = ""
            For i = 1 To Len(plainteks.Text)
                x = Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
                CI = Asc(x)
                CI = (plainteks.Text + kunci.Text) Mod 26
                x = Chr(CI)
                chiperteks.Text = chiperteks.Text & x
            Next
            chiperteks.Text = enkripsi(plainteks.Text, kunci.Text)
        End Sub

        Private Sub Btndeskript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btndeskript.Click
            Dim x As String
            Dim CI As Integer
            Dim KI As Integer
            Dim PI As Integer
            chiperteks.Text = ""
            For i = 1 To Len(plainteks.Text)
                x = Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
                PI = Asc(x)
                PI = (CI - KI) Mod 26
                x = Chr(PI)
                chiperteks.Text = chiperteks.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 Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            chiperteks.Text = ""
            plainteks.Text = ""
            kunci.Text = ""

        End Sub
    End Class
 

Tidak ada komentar:

Posting Komentar