Sabtu, 11 Januari 2014

Pemogramman Kriptografi


Pemogramman Kriptografi

Ø  Form menu Utama
Desainlah Form Menu Utama berikut ini 
 

Listing Programnya :
Public Class Form1
    Private Sub KriptografiCToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptografiCToolStripMenuItem.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 KriptograToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KriptograToolStripMenuItem.Click
        Form4.MdiParent = Me
        Form4.Show()
    End Sub

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

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


 
        End
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        KriptografiCToolStripMenuItem.PerformClick()
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        KriptografiVernamToolStripMenuItem.PerformClick()
    End Sub

    Private Sub ToolStripButton3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton3.Click
        KriptograToolStripMenuItem.PerformClick()
    End Sub

    Private Sub ToolStripButton4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton4.Click
        KriptografiToolStripMenuItem.PerformClick()
    End Sub

    Private Sub ToolStripButton5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton5.Click
        End
    End Sub
End Class
Hasil Programnya :
 

 
Ø  Kriptografi Caesar
Desainlah Form Berikut ini :
 


 
Listing Programnya :
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 btndekripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndekripsi.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 Programnya
Enkripsi :




 

 
Dekripsi ;

 

 Desanlah form berikut ini :


Ø  Kriptografi Vernam
 



Listing programnya :
Public Class Form3

    Private Sub Form3_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.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 = 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)) - 65
            nKunci = Asc(Mid(sKey, j, 1)) - 65
            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc) + 65)
        Next i
        chipertext.Text = sPlain
    End Sub

    Private Sub plaintext_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles plaintext.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





 
Hasil programnya :


 



 
Ø  Kriptografi Gonsfeld
Desainlah Form Berikut ini :





 



 
Listing Programnya :
Public Class Form4

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.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 = 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)) - 65
            nKunci = (Mid(sKey, j, 1))
            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc) + 65)
        Next i
        chipertext.Text = sPlain
    End Sub

    Private Sub plaintext_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles plaintext.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
        Dim tombol As Integer = Asc(e.KeyChar)
        If Not (tombol = 1) And (tombol = 1) Then
            e.Handled = True
        End If
    End Sub
End Class
HASIL PROGRAMNYA :




 



 
Ø  Kriptografi Vegenere

Desainlah form berikut ini :


 



 
Listing programnya :
Public Class Form5

    Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
        chipertext.Text = Enkripsi(plaintext.Text, kunci.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
Hasil program :