Sabtu, 18 Januari 2014

Kriptografi

Disini saya akan menampilkan hasil kriptografi dalam berbagai macam dengan menggunakan visual studio 2008 ,berikut adalah desainnya:


Public Class Form1

    Private Sub KriptografiCaesarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptografiCaesar.Click
        Form2.MdiParent = Me
        Form2.Show()
    End Sub

    Private Sub KriptografiVernamToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptografiVernamToolStripMenuItem.Click
        Form3.MdiParent = Me
        Form3.Show()
    End Sub

    Private Sub KriptografiGronslendToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptografiGronslendToolStripMenuItem.Click
        Form4.MdiParent = Me
        Form4.Show()
    End Sub

    Private Sub KriptografiVigenereToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptografiVigenereToolStripMenuItem.Click
        Form5.MdiParent = Me
        Form5.Show()
    End Sub

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

hasil:  


1.Kriptografi Caesar

Public Class Form2

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

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

End Class

Hasil desain diatas :
ENKRIPSI:

DESKRIPSI:     

2.Kriptografi 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 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 plainteks_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plainteks.TextChanged

    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

    Private Sub kunci_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kunci.TextChanged

    End Sub
End Class

Hasil ENKRIPSI :

3.Kriptografi Gronslend


Public Class Form4

    Private Sub Form4_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
        If ((e.KeyChar >= "0" And e.KeyChar <= "9") And e.KeyChar <> vbBack) Then e.Handled = True
    End Sub

    Private Sub plainteks_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plainteks.TextChanged

    End Sub

    Private Sub kunci_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles kunci.KeyPress
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then e.Handled = True
    End Sub

    Private Sub kunci_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kunci.TextChanged

    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)) - 48

            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc) + 65)
        Next i
        chiperteks.Text = sPlain
    End Sub
End Class

Hasilnya:  

4.Kriptografi Vegenere 

Public Class Form5

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

Hasil :  


Okey sampai disini postingan saya,terima kasih.






Tidak ada komentar:

Posting Komentar