Kamis, 16 Januari 2014

PEMROGRAMAN KRIPTOGRAFI VERNAM

Belajar Bahasa Pemrograman
1. Desainlah form seperti dibawah ini :



2. Kemudian buatlah listing program
Listing Program

Public Class Form2
    Private Sub Form2_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 sChiper 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

    Private Sub btnDeskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDeskripsi.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 sChiper As String = ""
        Dim nEnc As Integer
        j = 0
        sKata = Chiperteks.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
End Class

3. setelah dijalankan programnya muncul seperti gambar dibawah ini :


sekian info tentang PEMROGRAMAN KRIPTOGRAFI VERNAM.
silahkan dicoba ya :)