PROGRAM KRIPTOGRAFI PADA VB-2008

Pertama-tama Desain Form Menunya Seperti  berikut  :





















Kemudian Desain Form untuk...

 1.  CAESAR CHIPER :

























Berikut Listing Programnya :

Public Class Caesar_Chiper
    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(Plainteks.Text)
            x = Mid(Plainteks.Text, i, i)
            x = Chr(Asc(x) + 3)
            xkalimat = xkalimat + x
        Next
        Chiperteks.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(Chiperteks.Text)
            x = Mid(Chiperteks.Text, i, i)
            x = Chr(Asc(x) - 3)
            xkalimat = xkalimat + x
        Next
        Plainteks.Text = xkalimat
    End Sub

    Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
    End Sub

    Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
        Me.Close()
    End Sub
End Class



Nah Berikut Hasilnya :
























2. GRONSFELD CHIPER























Berikut Listing Programnya :

Public Class Gronsfeld_Chiper

    Private Sub Gronsfeld_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plainteks.Text = ""
        Chiperteks.Text = ""
    End Sub

    Private Sub BtnHitung_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
        Dim ind As Integer
        Dim huruf, kalimat As String
        Dim jumlah(25) As Integer
        kalimat = (Plainteks.Text).ToUpper
        For x = 1 To Microsoft.VisualBasic.Len(kalimat)
            huruf = kalimat.Substring(x - 1, 1)
            If (huruf >= "A") And (huruf <= "Z") Then
                ind = Asc(huruf) - 65
                jumlah(ind) += 1
            End If
        Next
        Chiperteks.Text = ""
        For i As Integer = 0 To 25
            huruf = Chr(i + 65)
            If jumlah(i) > 0 Then
                Chiperteks.Text = Chiperteks.Text & huruf & " = " & jumlah(i) & vbCrLf
            End If
        Next
    End Sub

    Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
        Me.Close()
    End Sub

    Private Sub Key_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 BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
    End Sub
End Class


Nah Berikut Hasilnya :























3. VERNAM CHIPER























Berikut Listing Programnya : 

Public Class Vernam_Chiper

    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 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 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 BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""
    End Sub
End Class


Nah Berikut Hasilnya :  























4. VIGENERE CHIPER






















Berikut Listing Programnya :

Public Class Vigenere_Chiper


    Private Sub Vigenere_Chiper_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

    Private Sub Plainteks_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Plainteks.KeyPress
        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 BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
    End Sub
End Class

Berikut Hasilnya :
























5. DES CHIPER






















Berikut Listing Programnya :


Imports System.IO
Imports System.Security.Cryptography
Imports System.Text

Public Class DES_Chiper
    Private Sub BtnEnkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
        Plainteks.Text = "abcdef"
        Dim enc As Encoder = System.Text.Encoding.Unicode.GetEncoder()
        Dim unicodeText As Byte()
        unicodeText = DirectCast(Array.CreateInstance(GetType(Byte), Plainteks.Text.Length * 2), Byte())
        enc.GetBytes(Plainteks.Text.ToCharArray(), 0, Plainteks.Text.Length, unicodeText, 0, True)
        Dim objmd5 As MD5 = New MD5CryptoServiceProvider ' Untuk enkripsi MD5
        'Dim objmd5 As MD5 = New SHA1CryptoServiceProvider() ' Untuk enkripsi SHA1
        'Dim objmd5 As MD5 = New DESCryptoServiceProvider() ' Untuk enkripsi DES
        'Dim objmd5 As MD5 = New RSACryptoServiceProvider ' Untuk enkripsi RSA
        Dim result As Byte() = objmd5.ComputeHash(unicodeText)
        Dim sb As StringBuilder = New StringBuilder()
        Dim i As Integer
        For i = 0 To result.Length - 1
            sb.Append(result(i).ToString("X2"))
        Next
        Chiperteks.Text = sb.ToString()
        'Anda dapat mengganti "abcdef" dengan kata yang anda butuhkan, dan menggunakan tipe enkripsi yang lain yang anda inginkan dengan mengaktifkan baris berikut :
        'Dim objmd5 As MD5 = New MD5CryptoServiceProvider ' Untuk enkripsi MD5
        'Dim objmd5 As MD5 = New SHA1CryptoServiceProvider() ' Untuk enkripsi SHA1
        'Dim objmd5 As MD5 = New DESCryptoServiceProvider() ' Untuk enkripsi DES
        'Dim objmd5 As MD5 = New RSACryptoServiceProvider ' Untuk enkripsi RSA
    End Sub

    Private Sub BtnHapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Chiperteks.Text = ""
    End Sub
End Class



Berikut Hasilnya :
























6. RC4





















Berikut Listing Programnya :

Public Class RC4

    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 BtnEnkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEnkripsi.Click
        Chiperteks.Text = Rc4(Plainteks.Text, Kunci.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnHapus.Click
        Plainteks.Text = ""
        Kunci.Text = ""
        Chiperteks.Text = ""
    End Sub
End Class



Berikut Hasilnya :






















Berikut Listing Program agar  dapat dijalankan di Form Menu :

Public Class Form1

    Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
        Caesar_Chiper.Show()
    End Sub

    Private Sub GronsfeldChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfeldChiperToolStripMenuItem.Click
        Gronsfeld_Chiper.Show()
    End Sub

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

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

    Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
        Vigenere_Chiper.Show()
    End Sub

    Private Sub DESChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DESChiperToolStripMenuItem.Click
        DES_Chiper.Show()
    End Sub
End Class

SELAMAT MENCOBA !!!

PEMROGRAMAN VB-2008
Share this article :
 

+ komentar + 1 komentar

30 Agustus 2019 pukul 04.29

mohon solusi nya om!!!

di metode RC4 saya ada kendala di,
System.text.StringBuilder,
sb.Append,
Sb.ToString,

apakah yg salah ya om??

Posting Komentar
 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. SIMPLE BLOG - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger