Senin, 01 Juli 2013

Tugas Kriptografi

KRIPTOGRAFI

Buat Design Menu Utama :



 


  1. VERNAM CHIPER :
   
          Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""
    End Sub

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


 Hasilnya :





 2. CEASAR CHIPER 



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 Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.Click
        Dim jumlah As Double = Len(Plainteks.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(Plainteks.Text, i, 1)
            bil = Asc(x) + 3
            x = Chr(bil)
            x_kalimat = x_kalimat + x
        Next i
        Chiperteks.Text = x_kalimat

    End Sub
End Class

   Hasilnya :


 



 3. VEGENERE CHIPER


 Public Class Form1

   
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""
    End Sub

    Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.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)) + 0
            nKunci = Asc(Mid(sKey, J, 1)) + 0
            nEnc = ((nKata + nKunci) Mod 256)
            sPlain = sPlain & Chr((nEnc))
        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
 

Hasilnya :


 

4. RC4


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""
    End Sub
    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 Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.Click
        Chiperteks.Text = Rc4(Plainteks.Text, Kunci.Text)
    End Sub
End Class
   

Hasilnya :

 



 5. DES CHIPER


  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 Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.Click
        'Dim key As String, kunciChar As String, katabaru As String
        Dim Pos As Long
        Dim i As Long, Side1 As String, Side2 As String
        Dim nEnc As Long
        Dim j As Integer
        Pos = 1
        For i = 1 To Len(Plainteks.Text)
            Plainteks.Text = Mid(Plainteks.Text, i, 1)
            kunci.Text = Mid(kunci.Text, Pos, 1)
            Chiperteks.Text = Chiperteks.Text & Chr(Asc(Plainteks.Text)) Or Asc(Kunci.Text)
            If Pos = Len(kunci) Then Pos = 0
            Pos = Pos + 1
        Next i
        j = Len(Chiperteks.Text) Mod 2 = 0
        If j Then
            Side1 = Strings.Left(Chiperteks.Text, (Len(Chiperteks.Text) / 2))
            Side2 = Strings.Right(Chiperteks.Text, (Len(Chiperteks.Text) / 2))
            Chiperteks.Text = Side1 & Side2
        End If
        nEnc = Chiperteks.Text
    End Sub
End Class
 

Hasilnya :




6.  GRONSFELD


 Public Class Form1

    Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.Click
        Chiperteks.Text = enkrips(Plainteks.Text, Kunci.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

     Hasilnya :