Saturday, 29 June 2013

Program Citra


1.caesar





Public Class Caesar

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.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 Caesar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Chiperteks.Text = ""
        Plainteks.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 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

2.gronsfeld



Public Class Gronsfeld

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.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 Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDeskripsi.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 Gronsfeld_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        chiperteks.Text = ""
        plainteks.Text = ""
        kunci.Text = ""
    End Sub
End Class

3.vernam



Public Class vernam
    Private Sub vernam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plainteks.Text = ""
        kunci.Text = ""
        chiperteks.Text = ""

    End Sub

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.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

4.vigenere



Public Class Form1

    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



Categories: ,

0 komentar:

Post a Comment