Sabtu, 29 Juni 2013

KRIPTOGRAFI

Public Class Form1

  

    Private Sub KELUARToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KELUARToolStripMenuItem.Click
        End
    End Sub

    Private Sub CAESARToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CAESARToolStripMenuItem.Click
        Form2.Show()

    End Sub

    Private Sub VIGENEREToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VIGENEREToolStripMenuItem.Click
        Form3.Show()

    End Sub

    Private Sub VERNAMToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VERNAMToolStripMenuItem.Click
        vernam.Show()

    End Sub

    Private Sub COLUMNToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles COLUMNToolStripMenuItem.Click
        column.Show()

    End Sub

    Private Sub REVERSEToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles REVERSEToolStripMenuItem.Click
        reverse.Show()
     Private Sub DESToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESToolStripMenuItem.Click
        DES.Show()

    End Sub
    End Sub
End Class

Public Class Form2

    Private Sub enchiper_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enchiper.Click
        Dim jumlah As Double = Len(plaintext.Text)
        Dim x As String
        Dim xkalimat As String = ""
        Dim i As Double
        Dim bil As Integer
        For i = 1 To jumlah
            x = Mid(plaintext.Text, i, 1)
            bil = Asc(x) + 3
            x = Chr(bil)
            xkalimat = xkalimat + x
        Next i
        chipertext.Text = xkalimat
    End Sub

    Private Sub chipertext_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chipertext.TextChanged

    End Sub

    Private Sub Label1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label1.Click

    End Sub
End Class



Public Class Form3

    Private Sub enk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enk.Click
        cip.Text = Enkripsi(plain.Text, key.Text)
    End Sub
    Function Enkripsi(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
        Enkripsi = sPlain
    End Function
End Class
        D


Public Class Form3

    Private Sub enk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enk.Click
        cip.Text = Enkripsi(plain.Text, key.Text)
    End Sub
    Function Enkripsi(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
        Enkripsi = sPlain
    End Function
End Class


Public Class Form1

  
    Private Sub enk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enk.Click
        cip.Text = enkripsi(plain.Text, key.Text, col.Text)
    End Sub
    Private Function enkripsi(ByVal plain As String, ByVal col As Integer, ByVal Key As String) As String
        Dim c1 As Integer
        Dim i As Long
        Dim j As Integer
        Dim k As Integer
        Dim r As Integer
        Dim strPlaintext2 As String
        Dim strCiphertext As String
        Dim colArray(1, 1) As Integer
        Dim nRow As Integer
        strPlaintext2 = ""

        For i = 1 To plain.Length
            c1 = Asc(Mid(plain, i, 1))
            If (c1 >= 65 And c1 <= 90) Then
                strPlaintext2 = strPlaintext2 & Chr(c1)
            End If
        Next i

        Dim remainder As Integer
        remainder = strPlaintext2.Length Mod col
        If (remainder <> 0) Then
            For i = 1 To (col - remainder)
                strPlaintext2 = strPlaintext2 & "A"
            Next i
        End If
        nRow = CInt(Math.Ceiling(CDbl(strPlaintext2.Length) / CDbl(col)))
        ReDim colArray(nRow, col)
        k = 1
        For i = 0 To (nRow - 1)
            For j = 0 To (col - 1)
                If (k <= strPlaintext2.Length) Then
                    colArray(i, j) = Asc(Mid(strPlaintext2, k, 1))
                    k = k + 1
                Else
                    colArray(i, j) = Asc("A")
                End If
            Next j
        Next i
        strCiphertext = ""
        Dim str1 As String = ""
        For i = 0 To (col - 1)
            k = i + 1
            For j = 1 To Key.Length
                If (k = CInt(Mid(Key, j, 1))) Then
                    For r = 0 To (nRow - 1)
                        strCiphertext = strCiphertext & Chr(colArray(r, j - 1))
                    Next r
                End If
            Next j
        Next i
        enkripsi = strCiphertext
    End Function



End Class





Public Class Form1


    Private Function ReverseEncipher(ByVal strPlaintext As String) As String
        Dim c1 As String
        Dim strCiphertext As String
        Dim strWord As String
        Dim plainLen As Integer
        Dim i As Long
        ' panjang string strKey dan strPlaintext
        plainLen = strPlaintext.Length()
        strCiphertext = ""
        strWord = ""
        For i = 1 To plainLen
            c1 = Asc(Mid(strPlaintext, i, 1))
            If ((c1 >= 65) And (c1 <= 90)) Then
                strWord = Chr(c1) & strWord
            Else
                strCiphertext = strCiphertext & strWord & Chr(c1)
                strWord = ""
            End If
        Next
        strCiphertext = strCiphertext & strWord
        Return strCiphertext
    End Function
   
   
    Private Sub enk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enk.Click
        ciphertext.Text = ReverseEncipher(plaintext.Text)
    End Sub
End Class
                                                   



Public Class des

    Private Sub des_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plain.Text = ""
        cip.Text = ""

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim x As String = ""
        Dim xkalimat As String = ""
        For i = 1 To Len(cip.Text)
            x = Mid(cip.Text, i, i)
            x = Chr(Asc(x) - 3)
            xkalimat = xkalimat + x
        Next
        plain.Text = xkalimat
    End Sub

End Class





Tidak ada komentar:

Posting Komentar