Minggu, 30 Juni 2013

KRIPTOGRAFI

TUGAS KRIPTOGRAFI 


1. CHESAR CHIPER

CODINGNYA:

Public Class Menu_Utama



    Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
        Caeser_Chiper.MdiParent = Me
        Caeser_Chiper.Show()
    End Sub

    Private Sub GronsfeldChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfeldChiperToolStripMenuItem.Click
        Grondfeld_Chiper.MdiParent = Me
        Grondfeld_Chiper.Show()
    End Sub

    Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
        Vernam_Chiper.MdiParent = Me
        Vernam_Chiper.Show()
    End Sub

    Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
        Vegenere_Chiper.MdiParent = Me
        Vegenere_Chiper.Show()
    End Sub

    Private Sub DesChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DesChiperToolStripMenuItem.Click
        Des_Chiper.MdiParent = Me
        Des_Chiper.Show()
    End Sub

    Private Sub RC4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RC4ToolStripMenuItem.Click
        RC4.MdiParent = Me
        RC4.Show()
    End Sub

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

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub KeluarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem1.Click
        End
    End Sub
End Class



Public Class Caeser_Chiper

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.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 Deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Deskripsi.Click
        Dim jumlah As Double = Len(Chiperteks.Text)
        Dim x As String
        Dim xkalimat As String = ""
        Dim i As Double
        Dim bil As Integer
        For i = 1 To jumlah
            x = Mid(Chiperteks.Text, i, 1)
            bil = Asc(x) - 3
            x = Chr(bil)
            xkalimat = xkalimat + x
        Next i
        Plainteks.Text = xkalimat
    End Sub

End Class

HASILNYA :


2. GRONSFIELD

CODINGNYA : 

Public Class Menu_Utama

    Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
        Caeser_Chiper.MdiParent = Me
        Caeser_Chiper.Show()
    End Sub

    Private Sub GronsfeldChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfeldChiperToolStripMenuItem.Click
        Grondfeld_Chiper.MdiParent = Me
        Grondfeld_Chiper.Show()
    End Sub

    Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
        Vernam_Chiper.MdiParent = Me
        Vernam_Chiper.Show()
    End Sub

    Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
        Vegenere_Chiper.MdiParent = Me
        Vegenere_Chiper.Show()
    End Sub

    Private Sub DesChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DesChiperToolStripMenuItem.Click
        Des_Chiper.MdiParent = Me
        Des_Chiper.Show()
    End Sub

    Private Sub RC4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RC4ToolStripMenuItem.Click
        RC4.MdiParent = Me
        RC4.Show()
    End Sub

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

    Private Sub MenuStrip1_ItemClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolStripItemClickedEventArgs) Handles MenuStrip1.ItemClicked

    End Sub

    Private Sub KeluarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem1.Click
        End
    End Sub
End Class

HASILNYA :


3. 

CODINGNYA : VERNAM CHIPER

Public Class Vernam_Chiper

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

End Class

HASILNYA :


4. VEGENERE CHIPER

CODINGNYA

Public Class Vegenere_Chiper

    Private Sub Vegenere_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plaintext.Text = ""
        Chipertext.Text = ""
        Kunci.Text = ""
    End Sub

    Private Sub Enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enkripsi.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 = Plaintext.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
        Chipertext.Text = sPlain
    End Sub

End Class

HASILNYA



5. DES CHIPER

CODINGNYA

Public Class Des_Chiper

    Private Sub Enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enkripsi.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(Plaintext.Text)
            Plaintext.Text = Mid(Plaintext.Text, i, 1)
            kunci.Text = Mid(kunci.Text, Pos, 1)
            Chipertext.Text = Chipertext.Text & Chr(Asc(Plaintext.Text)) Or Asc(Kunci.Text)
            If Pos = Len(kunci) Then Pos = 0
            Pos = Pos + 1
        Next i
        j = Len(Chipertext.Text) Mod 2 = 0
        If j Then
            Side1 = Strings.Left(Chipertext.Text, (Len(Chipertext.Text) / 2))
            Side2 = Strings.Right(Chipertext.Text, (Len(Chipertext.Text) / 2))
            Chipertext.Text = Side1 & Side2
        End If
        nEnc = Chipertext.Text
    End Sub

    Private Sub Des_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plaintext.Text = ""
        Chipertext.Text = ""
    End Sub
End Class

HASILNYA



6. RC4

CODINGNYA

Public Class RC4

    Private Sub RC4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plaintext.Text = ""
        Chipertext.Text = ""
        Kunci.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 Enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Enkripsi.Click
        Chipertext.Text = Rc4(Plaintext.Text, Kunci.Text)
    End Sub
End Class

HASILNYA







Tidak ada komentar:

Posting Komentar