Minggu, 30 Juni 2013

Kriptografi


PROGRAM KELUAR
Public Class Form1

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

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

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

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

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

    Private Sub KeluarToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles KeluarToolStripMenuItem1.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

    Private Sub Caesar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        chipertext.Text = ""
    End Sub

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

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





Public Class Vernam

    Private Sub Vernam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.Text = ""
    End Sub

    Private Sub enkripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enkripsi.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
ENKRIPSI

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 As String) 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

    Private Sub deskripsi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deskripsi.Click

    End Sub
End Class


Minggu, 02 Juni 2013

program pemakaian listrik


Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Pelanggan.Items.Add("Med")
        Pelanggan.Items.Add("Bel")
        Pelanggan.Items.Add("Tem")
        Pelanggan.Items.Add("Mar")
        Pelanggan.Items.Add("Bin")
        Pelanggan.Items.Add("Pak")

        Tipe.Items.Add("Toko")
        Tipe.Items.Add("Rumah")
        Tipe.Items.Add("Swalayan")
        Tipe.Items.Add("Pabrik")

        For i = 1 To 100
            jp.Items.Add(i)
        Next i

        Call buattabel()
    End Sub

    Private Sub Pelanggan_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pelanggan.SelectedIndexChanged
        Select Case Pelanggan.Text
            Case "Med" : daerah.Text = "Medan"
            Case "Bel" : daerah.Text = "Belawan"
            Case "Tem" : daerah.Text = "Aksara"
            Case "Mar" : daerah.Text = "Marendal"
            Case "Bin" : daerah.Text = "Binjai"
            Case "Pak" : daerah.Text = "L.Pakam"
        End Select
    End Sub

    Private Sub Tipe_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Tipe.SelectedIndexChanged
        Select Case Tipe.Text
            Case "Toko" : Biaya.Text = "150000"
            Case "Rumah" : Biaya.Text = "50000"
            Case "Swalayan" : Biaya.Text = "400000"
            Case "Pabrik" : Biaya.Text = "1000000"
        End Select
        Select Case Tipe.Text
            Case "Toko" : KWH.Text = "500"
            Case "Rumah" : KWH.Text = "200"
            Case "Swalayan" : KWH.Text = "1500"
            Case "Pabrik" : KWH.Text = "10000"
        End Select
        pajak.Text = 0.015 * Biaya.Text
    End Sub

    Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click

    End Sub

    Private Sub Biaya_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Biaya.TextChanged

    End Sub

    Private Sub btnproses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnproses.Click

        If Tipe.Text = "Toko" Then
            Total.Text = 500
        ElseIf Tipe.Text = "rumah" Then
            Total.Text = 200
        ElseIf Tipe.Text = "swalayan" Then
            Total.Text = 1500
        ElseIf Tipe.Text = "pabrik" Then
            Total.Text = 10000
        Else
            Total.Text = 0
        End If
        Total.Text = Val(Total.Text * jp.Text) + Val(Biaya.Text) + Val(KWH.Text) - Val(pajak.Text)
    End Sub

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

    End Sub
    Sub buattabel()
        lv.Columns.Add("pelanggan", 100, HorizontalAlignment.Center)
        lv.Columns.Add("daerah", 100, HorizontalAlignment.Left)
        lv.Columns.Add("tipe", 100, HorizontalAlignment.Left)
        lv.Columns.Add("biaya", 100, HorizontalAlignment.Left)
        lv.Columns.Add("KWH", 100, HorizontalAlignment.Left)
        lv.Columns.Add("JP", 100, HorizontalAlignment.Center)
        lv.Columns.Add("TOTAL", 80, HorizontalAlignment.Center)
        lv.Columns.Add("pajak", 80, HorizontalAlignment.Center)
        lv.View = View.Details
        lv.GridLines = True
        lv.FullRowSelect = True
    End Sub
    Sub isitabel()
        Dim lst As New ListViewItem
        lst.Text = Pelanggan.Text
        lst.SubItems.Add(daerah.Text)
        lst.SubItems.Add(Tipe.Text)
        lst.SubItems.Add(Biaya.Text)
        lst.SubItems.Add(KWH.Text)
        lst.SubItems.Add(jp.Text)
        lst.SubItems.Add(Total.Text)
        lst.SubItems.Add(pajak.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()
        Pelanggan.Text = ""
        Total.Text = ""
        Tipe.Text = ""
        Biaya.Text = ""
        KWH.Text = ""
        jp.Text = ""
        Total.Text = ""
        pajak.Text = ""
    End Sub

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

    Private Sub jp_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
    
    End Sub

    Private Sub jp_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles jp.SelectedIndexChanged

    End Sub
End Class