Kriptografi Sederhana



Selamat pagi sobat blogger, pada pagi yang sangat cerah ini, saya akan berbagi ilmu sedikit tentang kriptografi, tapi kriptografi itu apa yaaa.... !
Kriptografi (cryptography) berasal dari bahasa
Yunani, terdiri dari dua suku kata yaitu kripto dan graphia. Kripto artinya menyembunyikan, sedangkan graphia artinya tulisan. Kriptografi adalah ilmu yang mempelajari teknik-teknik matematika yang berhubungan dengan aspek keamanan informasi, seperti kerahasiaan data, keabsahan data, integritas data, serta autentikasi data .Tetapi tidak semua aspek keamanan informasi dapat diselesaikan dengan kriptografi. Kriptografi dapat pula diartikan sebagai ilmu atau seni untuk menjaga keamanan pesan.
Pada prinsipnya, Kriptografi memiliki 4 komponen utama yaitu:
1.     Plaintext, yaitu pesan yang dapat dibaca
2.     Ciphertext, yaitu pesan acak yang tidka dapat dibaca
3.     Key, yaitu kunci untuk melakukan teknik kriptografi
4.     Algorithm, yaitu metode untuk melakukan enkrispi dan dekripsi

Kemudian, proses yang akan dibahas dalam artikel ini meliputi 2 proses dasar pada Kriptografi yaitu:
1.     Enkripsi (Encryption)
2.     Dekripsi (Decryption)

Nah... dalam postingan kali ini, ada 4 kriptografi yang akan kita bahas yaitu, Kriptografi ceesar, kriptografi vernam, kriptografi groundsfield dan kriptografi vegenere, yang masing masing mempunyai maksud yg sama yaitu untuk mengaman kan data.
Ok... langsung saja, kita masuki kriptografi pertama

   A.    Kriptografi ceesar

ketikkan listing berikut:
Add caption
Public Class Kriptografi_Caesar
    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(plaint.Text)
            x = Mid(plaint.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 a As String = ""
        Dim akalimat As String = ""
        For i = 1 To Len(plaint.Text)
            a = Mid(plaint.Text, i, i)
            a = Chr(Asc(a) - 3)
            akalimat = akalimat + a
        Next
        chiper.Text = akalimat
    End Sub
End Class

   B.      Kriptografi vernam

ketikak listing berikut:
Public Class Kriptografi_vernam
    Private Sub Kriptografi_Karna_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plainteks.Text = ""
        DDD.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 splaint As String = ""
        Dim nenc As Integer
        j = 0

        skata = plainteks.Text
        jum = Len(skata)
        skey = DDD.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, i, 1)) - 65
            nenc = ((nkata + nkunci) Mod 26)
            splaint = splaint & Chr((nenc) + 65)
        Next i
        chiperteks.Text = splaint
    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 DDD.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 btn_deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_deskripsi.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 splaint As String = ""
        Dim nenc As Integer
        j = 0

        skata = plainteks.Text
        jum = Len(skata)
        skey = DDD.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, i, 1)) - 65
            nenc = ((nkata + nkunci) Mod 26)
            splaint = splaint & Chr((nenc) + 65)
        Next i
        chiperteks.Text = splaint
    End Sub
End Class

   C.      Kriptografi ground sfield

 ketikkan listing berikut;
 Public Class Kriptografi_Gronsfield
    Private Sub Kriptografi_Karna_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plainteks.Text = ""
        DDD.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 splaint As String = ""
        Dim nenc As Integer
        j = 0

        skata = plainteks.Text
        jum = Len(skata)
        skey = DDD.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)
            splaint = splaint & Chr((nenc) + 65)
        Next i
        chiperteks.Text = splaint
    End Sub
    Private Sub btn_deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_deskripsi.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 splaint As String = ""
        Dim nenc As Integer
        j = 0

        skata = plainteks.Text
        jum = Len(skata)
        skey = DDD.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, i, 1)) - 48
            nenc = ((nkata + nkunci) Mod 26)
            splaint = splaint & Chr(nenc - 65)
        Next i
        chiperteks.Text = splaint
    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 DDD.KeyPress
        e.KeyChar = UCase(e.KeyChar)
        Dim tombol As Integer = Asc(e.KeyChar)
        If Not ((e.KeyChar >= "0" And e.KeyChar <= "9") Or e.KeyChar = vbBack) Then
            e.Handled = True
        End If
    End Sub
End Class

   D.      Kriptografi vegenere


Cara mainnya adalah
Public Class Kriptografi_Vigenere
    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
    Private Sub btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenkripsi.Click
        chipertext.Text = Enkripsi(plaintext.Text, kunci.Text)
    End Sub
End Class

sekian dulu ya gan... moga bermanfaat buat kita semua, dan baca juga tentang program Pembayaran Listrik Menggunakan VB.2008.


Share this post :

Posting Komentar

komentar anda sangat kami butuhkan, namun tolong gunakan bahasa yang sopan.!

 
Support : Raflyzea Agara | Johny Template | Mas Template
Copyright © 2011. Raflyzea.agara - All Rights Reserved
Template Created by Raflyzea Agara Published by Mas Template
Proudly powered by Blogger