Salam Anak Nias "Ya'ahowu..!"

Selamat Datang di Blog Sederhanaku ini.

Sabtu, 29 Juni 2013

Tugas Pemograman Visual I Tentang Kritografi

 
                           gambar1. Menu Utama 


Berikut ini adalah listing programnya :
Public Class Form1
    Private Sub KeluarToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem.Click
        End
    End Sub
    Private Sub CaesarChToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChToolStripMenuItem.Click
        caesar_chiper.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
A A. Kriptografi Caesar Chiper
Desain program
 
           gambar2. Caesar Cipher

Berikut ini adalah listing programnya :
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
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        plaintext.Text = ""
        chipertext.Text = ""
    End Sub
    Private Sub btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        End
    End Sub
    Private Sub btnkeluar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub
End Class

A B. Kriptografi Vernam Cipher
Desain awal program :
 

                          gambar3. Vernam Cipher




Berikut ini adalah listing programnnya :
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 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 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
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.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
A C. Kriptografi Vigenere Cipher
Desain program :
 
          gambar4. Vigenere Cipher 


Public Class vigenere_chiper
    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
    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 btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.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 vigenere_chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    End Sub
End Class
     D.  Kriptografi Autokey
    
Desain awal :
                                  gambar5. Autokey
    Private Sub autokey_chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.Text = ""
    End Sub
    Private Function btn_AutokeyEncipher(ByVal strPlaintext As String, ByRef strKey As String) As String
        Dim i As Long
        Dim j As Long
        Dim c1 As Integer
        Dim c2 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 btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        Me.Close()
    End Sub
    Private Sub btnhapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnhapus.Click
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.Text = ""
    End Sub
    Private Sub btnenkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Encipher.Click
      chipertext.Text = AutokeyEncipher(plaintext.Text, kunci.Text)
    End Sub
End Class
E.Kriptografi Des chiper
Desain awal 
                                       gambar6. Des Cipher





Public Class Des_chiper
    Private Sub Des_chiper_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plain.Text = ""
        chip.Text = ""
    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(chip.Text)
            x = Mid(chip.Text, i, i)
            x = Chr(Asc(x) - 3)
            xkalimat = xkalimat + x
        Next
        plain.Text = xkalimat
    End Sub
    Private Sub hapus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus.Click
        plain.Text = ""
        chip.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

Minggu, 02 Juni 2013

Soal Quis No.2 di Mesran dot Net

Jawaban Quis On-Line Mata Kuliah Visual Pemogramman I pada Website Mesran.net


Untuk Mendesain tampilan di atas
Inputkan 7 buah Lebel
2  buah ComboBox
5 buah text Box
6 buah Buttob
1 bh ListVIew
2 Buah GroupBox

Tampilan Awalnya

Listing Programmanya :


Public Class Form1

    Sub rancangTabel()
        With LV
            .Columns.Add("Kode", 50, HorizontalAlignment.Center)
            .Columns.Add("Nama Berang", 80, HorizontalAlignment.Left)
            .Columns.Add("Harga", 80, HorizontalAlignment.Center)
            .Columns.Add("Jumlah", 55, HorizontalAlignment.Center)
            .Columns.Add("Total Harga", 70, HorizontalAlignment.Center)
            .Columns.Add("Diskon", 70, HorizontalAlignment.Center)
            .Columns.Add("Total Bayar", 70, HorizontalAlignment.Center)
            .GridLines = True
            .FullRowSelect = True
            .View = View.Details
        End With
    End Sub
    Sub MasukTabel()
        Dim frendiks As New ListViewItem
        frendiks.Text = kode.Text
        frendiks.SubItems.Add(nama.Text)
        frendiks.SubItems.Add(harga.Text)
        frendiks.SubItems.Add(jumlah.Text)
        frendiks.SubItems.Add(total.Text)
        frendiks.SubItems.Add(diskon.Text)
        frendiks.SubItems.Add(total_bayar.Text)
        LV.Items.Add(frendiks)
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        rancangTabel()
        kode.Items.Add("TS001")
        kode.Items.Add("TS002")
        kode.Items.Add("TS003")
        kode.Items.Add("TS004")
        Dim x As Integer
        For x = 1 To 10
            jumlah.Items.Add(x)
        Next
    End Sub
    Sub hapus()
        kode.Text = ""
        nama.Text = ""
        harga.Text = ""
        jumlah.Text = ""
        total.Text = ""
        diskon.Text = ""
        total_bayar.Text = ""
    End Sub

    Private Sub kode_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode.SelectedIndexChanged
        Dim x As String
        x = Microsoft.VisualBasic.Right(kode.Text, 3)
        Select Case x
            Case "001" : nama.Text = "Soni 15inchi"
            Case "002" : nama.Text = "Soni 22 inchi"
            Case "003" : nama.Text = "Soni 24 inchi"
            Case "004" : nama.Text = "Soni 32 inchi"

        End Select

        If kode.Text = "TS001" Then
            harga.Text = 1500000
        ElseIf kode.Text = "TS002" Then
            harga.Text = 1200000
        ElseIf kode.Text = "TS003" Then
            harga.Text = 1000000
        ElseIf kode.Text = "TS004" Then
            harga.Text = 1100000
        Else
            harga.Text = 0

        End If
    End Sub

    Private Sub jumlah_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jumlah.SelectedIndexChanged
        total.Text = Val(harga.Text) * Val(jumlah.Text)
        If total.Text >= 2500000 Then
            diskon.Text = Val(total.Text) * 0.1
        Else
            diskon.Text = 0
        End If
    End Sub

    Private Sub baru_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles baru.Click
        total_bayar.Text = Val(total.Text) - Val(diskon.Text)
    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        MasukTabel()
        hapus()
        kode.Focus()
    End Sub

    Private Sub batal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles batal.Click
        hapus()
    End Sub

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

    Private Sub hapussemua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapussemua.Click
        LV.Items.Clear()
    End Sub

  
    Private Sub hapus1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus1.Click
        If LV.SelectedItems.Count <> 0 Then
            LV.Items.Remove(LV.SelectedItems(0))
        Else
            MsgBox("Pilih Yang Mau di Hapus.!")
        End If
    End Sub
End Class


tampilan Setelah di Jalankan.

Sabtu, 01 Juni 2013

Yuk! Belajar Pemrograman Visual Basic dot Net Di Mesran.Net

Judul Soal Latihan Listview Perhitungan Penjualan Barang

Desain Tampilan Seperti Berikut ini

Tampilan sebelum Di jalan kan.


Berikut Listing Programmnya :


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RancangTabel()
        kode_barang.Items.Add("TSF001")
        kode_barang.Items.Add("TSF002")
        kode_barang.Items.Add("VGR001")
        kode_barang.Items.Add("VGR002")
        kode_barang.Items.Add("VGR003")
        no_pembelian.Focus()
    End Sub
    Sub RancangTabel()
        lv.Columns.Add("No.Pembelian", 100, HorizontalAlignment.Center)
        lv.Columns.Add("Kode Barang", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Nama Barang", 100, HorizontalAlignment.Center)
        lv.Columns.Add("Merek", 80, HorizontalAlignment.Center)
        lv.Columns.Add("Harga", 90, HorizontalAlignment.Center)
        lv.Columns.Add("Jumlah Beli", 50, HorizontalAlignment.Center)
        lv.Columns.Add("Total Harga", 80, HorizontalAlignment.Center)
        lv.GridLines = True
        lv.FullRowSelect = True
        lv.View = View.Details
    End Sub
    Sub hapus()
        no_pembelian.Text = ""
        kode_barang.Text = ""
        nama_barang.Text = ""
        merek.Text = ""
        harga.Text = ""
        jumlah_beli.Text = ""
        total.Text = ""
    End Sub
    Sub MasukTabel()
        Dim frendiks As New ListViewItem
        With frendiks
            .Text = no_pembelian.Text
            .SubItems.Add(kode_barang.Text)
            .SubItems.Add(nama_barang.Text)
            .SubItems.Add(merek.Text)
            .SubItems.Add(harga.Text)
            .SubItems.Add(jumlah_beli.Text)
            .SubItems.Add(total.Text)
            lv.Items.Add(frendiks)


        End With
    End Sub

    Private Sub lv_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lv.SelectedIndexChanged

    End Sub

    Private Sub kode_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kode_barang.SelectedIndexChanged

        Dim x As String
        Dim x2 As String
        x = Microsoft.VisualBasic.Mid(kode_barang.Text, 3, 1)
               x = Microsoft.VisualBasic.Left(kode_barang.Text, 2)
        If x = "TS" Then
            merek.Text = "TOSHIBA"
        ElseIf x = "VG" Then
            merek.Text = "V-Gen"
        End If


        x2 = Microsoft.VisualBasic.Right(kode_barang.Text, 3)
        If x2 = "001" Then
            nama_barang.Text = "Leptop"
        ElseIf x2 = "002" Then
            nama_barang.Text = "Flashdisk"
        End If

        If x = "TS" And x2 = "001" Then
            harga.Text = 105000
        ElseIf x = "TS" And x2 = "002" Then
            harga.Text = 75000
        ElseIf x = "VG" And x2 = "001" Then
            harga.Text = 90000
        ElseIf x = "VG" And x2 = "002" Then
            harga.Text = 60000
        Else
            harga.Text = 0
        End If
    End Sub

    Private Sub Label7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label7.Click

    End Sub

    Private Sub TextBox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah_beli.KeyPress
        If e.KeyChar = Chr(13) Then
            total.Text = Val(harga.Text) * jumlah_beli.Text
        End If
    End Sub

    Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jumlah_beli.TextChanged

    End Sub

    Private Sub simpan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles simpan.Click
        MasukTabel()
        hapus()
        no_pembelian.Focus()
    End Sub

    Private Sub bersih_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bersih.Click
        hapus()
        no_pembelian.Focus()
    End Sub

    Private Sub hapus_semua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_semua.Click
        If lv.SelectedItems.Count <> 0 Then
            lv.Items.Remove(lv.SelectedItems(0))
        Else
            MsgBox("Pilih Dulu Bro yang Mau Dihapus..!")
        End If
    End Sub

    Private Sub hapus_satu_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles hapus_satu.Click
        lv.Items.Clear()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        End
    End Sub
End Class


Tampilan Setelah Dijalankan. dan Hasilnya setelah disimpan.