Minggu, 30 Juni 2013

Tugas Praktikum Kriptografi


Public Class Form1

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

    Private Sub GransfieldChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GransfieldChiperToolStripMenuItem.Click
        DesChiper.Show()
    End Sub

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

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

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

    Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
        Dim i As MsgBoxResult
        i = MsgBox("Apa anda ingin keluar?", MsgBoxStyle.Information + MsgBoxStyle.YesNo, "Perhatian")
        If i = MsgBoxResult.Yes Then
            Close()
        End If
    End Sub
End Class


Public Class Caesar_Chiper

    Private Sub Caesar_Chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Plaintext.Text = ""
        Chipertext.Text = ""
    End Sub

    Private Sub Btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btnenkripsi.Click
        Dim jumlah As Double = Len(Plaintext.Text)
        Dim x As String
        Dim xkalimat As String = ""
        Dim i As Double
        Dim bil As Integer
        For i = 1 To jumlah
            x = Mid(Plaintext.Text, i, 1)
            bil = Asc(x) + 3
            x = Chr(bil)
            xkalimat = xkalimat + x
        Next i
        Chipertext.Text = xkalimat
    End Sub
End Class

 
Public Class Vernam_chiper

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

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

    End Sub

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


Public Class vigenere

    Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enkripsi.Click
        chipertext.Text = Eenkripsi(plaintext.Text, kunci.Text)
    End Sub
    Function Eenkripsi(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
        Eenkripsi = sPlain
    End Function

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

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

Public Class RC4

    Private Sub RC4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.Text = ""
    End Sub
    Private Function AutokeyEncipher(ByVal strPlaintext As String, ByRef strKey AsString) As String
        Dim i As Long
        Dim j As Long
        Dim c1 As Integer
        Dim strPlaintext2 As String
        Dim strKey2 As String
        Dim strCiphertext As String
        Dim strCiphertext2 As String
        Dim diffKeyLen As Integer
        Dim pAlphabet As Integer
        Dim cAlphabet As Integer
        Dim nShift As Integer
        '1. Hilangkan semua karakter yang bukan alfabet dari strPlaintext
        ' dan simpan sebagai strPlaintext2
        strPlaintext2 = ""
        For i = 1 To strPlaintext.Length
            c1 = Asc(Mid(strPlaintext, i, 1))
            If (c1 >= 65 And c1 <= 90) Then
                strPlaintext2 = strPlaintext2 & Chr(c1)
            End If
        Next i
        '2. Hilangkan semua karakter yang bukan alfabet dari strKey
        ' dan simpan sebagai strKey2
        strKey2 = ""
        For i = 1 To strKey.Length

            c1 = Asc(Mid(strKey, i, 1))
            If (c1 >= 65 And c1 <= 90) Then
                strKey2 = strKey2 & Chr(c1)
            End If
        Next i
        '3. Susun kunci baru strKey2 berdasarkan kunci awal strKey kemudian
        ' ditambah plaintext
        'perbedaan antara panjang plaintext dan kunci
        diffKeyLen = strPlaintext2.Length - strKey2.Length
        For i = 1 To diffKeyLen
            'c1 = Asc(Mid(strPlaintext2, i, 1))
            strKey2 = strKey2 & Mid(strPlaintext2, i, 1)
        Next i
        '4. Geser masing-masing huruf pada plaintext
        ' dengan huruf yang terkait pada key
        strCiphertext = ""
        For i = 1 To strPlaintext2.Length
            c1 = Asc(Mid$(strPlaintext2, i, 1))
            nShift = Asc(Mid$(strKey2, i, 1)) - 65
            If ((c1 >= 65) And (c1 <= 90)) Then
                pAlphabet = c1 - 65 ' get the alphabet sequence
                cAlphabet = (pAlphabet + nShift) Mod 26 ' shifted alphabet
                c1 = cAlphabet + 65 ' get character in 65 ... 90
            End If
            strCiphertext = strCiphertext & Chr(c1)
        Next i
        '5. Susun strCiphertext sesuai dengan urutan strPlaintext
        strCiphertext2 = ""
        strKey = ""
        j = 1
        For i = 1 To strPlaintext.Length
            c1 = Asc(Mid$(strPlaintext, i, 1))
            If ((c1 >= 65) And (c1 <= 90)) Then
                strCiphertext2 = strCiphertext2 & Mid(strCiphertext, j, 1)
                strKey = strKey & Mid(strKey2, j, 1)
                j = j + 1
            Else
                strCiphertext2 = strCiphertext2 & Chr(c1)
                strKey = strKey & " "
            End If
        Next i
        Return strCiphertext2
    End Function

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

    End Sub

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

    Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enkripsi.Click
        chipertext.Text = AutokeyEncipher(plaintext.Text, kunci.Text)
    End Sub
End Class

belajarrr lebih lanjut lagi yookkk di mesran.blogspot.com 






Minggu, 02 Juni 2013

YUK BELAJAR PEMROGRAMAN VISUAL BASIC DOT NET DI MESRAN.NET


Public Class Form1

    Private Sub kdbar_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kdbar.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Left(kdbar.Text, 2)
        Select Case x
            Case "TS" : merk.Text = "TOSHIBA"
            Case "VG" : merk.Text = "V-GEN"
        End Select

        Dim I As String
        I = Microsoft.VisualBasic.Right(kdbar.Text, 3)
        Select Case I
            Case "001" : nabar.Text = "FLASHDISK 4GB"
            Case "002" : nabar.Text = "FLASHDISK 2GB"
        End Select

        If x = "TS" And I = "001" Then
            harga.Text = 105000
        ElseIf x = "TS" And I = "002" Then
            harga.Text = 75000
        ElseIf x = "VG" And I = "001" Then
            harga.Text = 90000
        ElseIf x = "VG" And I = "002" Then
            harga.Text = 60000

        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        kdbar.Items.Add("TS001")
        kdbar.Items.Add("TS002")
        kdbar.Items.Add("VG001")
        kdbar.Items.Add("VG002")


        buatTabel()
    End Sub
    Sub bersih()
        nopem.Text = ""
        kdbar.Text = ""
        merk.Text = ""
        harga.Text = ""
        tohar.Text = ""
        jumbel.Text = ""
        nabar.Text = ""

    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 btnproses_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click
        tohar.Text = harga.Text * jumbel.Text
    End Sub

    Private Sub btnhapus2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus2.Click
        nopem.Text = ""
        kdbar.Text = ""
        jumbel.Text = ""
    End Sub

    Private Sub btnhapus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus1.Click
        nopem.Text = ""
        kdbar.Text = ""
        merk.Text = ""
        harga.Text = ""
        tohar.Text = ""
        jumbel.Text = ""
        nabar.Text = ""
    End Sub

    Private Sub LV_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LV.SelectedIndexChanged
    End Sub

    Sub buatTabel()

        LV.Columns.Add("No Pembelian", 80, HorizontalAlignment.Center)
        LV.Columns.Add("Kode Barang", 180, HorizontalAlignment.Left)
        LV.Columns.Add("Nama Barang", 180, HorizontalAlignment.Left)
        LV.Columns.Add("Merk", 180, HorizontalAlignment.Left)
        LV.Columns.Add("Harga", 180, HorizontalAlignment.Left)
        LV.Columns.Add("Jumlah Beli", 180, HorizontalAlignment.Left)
        LV.Columns.Add("Total Harga", 180, HorizontalAlignment.Left)
        LV.View = View.Details
        LV.GridLines = True
        LV.FullRowSelect = True

    End Sub


    Sub isiTabel()
        Dim lst As New ListViewItem
        lst.Text = nopem.Text
        lst.SubItems.Add(kdbar.Text)
        lst.SubItems.Add(nabar.Text)
        lst.SubItems.Add(merk.Text)
        lst.SubItems.Add(harga.Text)
        lst.SubItems.Add(jumbel.Text)
        lst.SubItems.Add(tohar.Text)
        LV.Items.Add(lst)

    End Sub


    Private Sub btnsimpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsimpan.Click
        isiTabel()
        nopem.Text = ""
        kdbar.Text = ""
        nabar.Text = ""
        merk.Text = ""
        harga.Text = ""
        jumbel.Text = ""
        tohar.Text = ""
    End Sub
End Class


Demikianlh postingan saya :
nama : Nur febrina sari baizuri
npm :1111035