Jumat, 17 Januari 2014

KRIPTOGRAFI

Latihan Kriptografi

Berikut ini adalah design dan cara-cara penyelesaiannya 
1.  Tampilan Dari Menu Utama 
Desaignnya :
Dan Berikut ini adalah cara memanggil form-form yang akan ditampilkan dari menu Utama

Public Class Form1
    Private Sub PEMOGRAMANKRIPTOGRAFIToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PEMOGRAMANKRIPTOGRAFIToolStripMenuItem.Click
        Form2.MdiParent = Me
        Form2.Show()
    End Sub
    Private Sub PEMOGRAMANKRIPTOGRAFIToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PEMOGRAMANKRIPTOGRAFIToolStripMenuItem1.Click
        Form3.MdiParent = Me
        Form3.Show()
    End Sub
    Private Sub KRIPTOGRAFIToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KRIPTOGRAFIToolStripMenuItem.Click
        Form4.MdiParent = Me
        Form4.Show()
    End Sub
    Private Sub KRIPTOGRAFIVEGENERIToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KRIPTOGRAFIVEGENERIToolStripMenuItem.Click
        Form5.MdiParent = Me
        Form5.Show()
    End Sub
End Class
Hasilnya :
2.  Tampilan Dari Pemograman Kriptografi Caesar Chiper
     Designnya :
 Listing Programnya:
Public Class Form2

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

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

    Private Sub keluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles keluar.Click
        Dim lia As Integer
        lia = MsgBox("anda mau keluar ?", MsgBoxStyle.YesNo)
        If lia = MsgBoxResult.Yes Then
            Me.Close()
        End If
    End Sub

    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        plaintext.Text = ""
        chipertext.Text = ""
    End Sub

    Private Sub kkkriptogrfi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kkkriptogrfi.Click
        Me.Hide()
        kkkriptogrfi.Show()
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub
End Class

Berikut hasilnya:
3.  Cara penyelesaian Pemograman Kriptografi Vernam Chiper
    Designya :
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 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)) - 65
            nkunci = Asc(Mid(skey, j, 1)) - 65
            nEnc = ((nkata + nkunci) Mod 26)
            splain = splain & Chr((nEnc))


        Next i
        chipertext.Text = splain
    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 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
End Class

Hasilnya:
4.  Cara Penyelesaian Pemograman Kriptografi Gronsfeld
  Designya :
Listing programnya:
Public Class Form4

    Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""

        chipertext.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
        jum = Len(Text)
        splain = ""
        skey = kunci.Text
        skata = 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))
            nEnc = (nkata + nkunci) Mod 26
            splain = splain & Chr((nEnc) + 65)


        Next i
        chipertext.Text = splain
    End Sub
End Class
Hasilnya:


 
5 . Cara penyelesaian Kriptografi Vigenere
 Designya :
Listing programnya:
Public Class Form5

    Private Sub Form5_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.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
        jum = Len(Text)
        splain = ""
        skey = kunci.Text
        skata = 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))
            nkunci = Asc(Mid(skey, j, 1))
            nEnc = ((nkata + nkunci) Mod 256)
            splain = splain & Chr((nEnc))


        Next i
        chipertext.Text = splain
    End Sub
End Class
Berikut hasilnya:

 

 

Tidak ada komentar:

Posting Komentar