Minggu, 30 Juni 2013

TUGAS KRIPTOGRAFI CAESAR CHIPER, GRONSFIELD CHIPER.




Public Class Form1

   
    Private Sub CaesarChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CaesarChiperToolStripMenuItem.Click
        Form2.MdiParent = Me
        Form2.Show()
    End Sub

    Private Sub GronsfieldChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GronsfieldChiperToolStripMenuItem.Click
        Form3.MdiParent = Me
        Form3.Show()
    End Sub

    Private Sub VernamChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VernamChiperToolStripMenuItem.Click
        Form4.MdiParent = Me
        Form4.Show()
    End Sub

    Private Sub VigenereChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VigenereChiperToolStripMenuItem.Click
        Form5.MdiParent = Me
        Form5.Show()
    End Sub

    Private Sub DesChiperToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DesChiperToolStripMenuItem.Click
        Form6.MdiParent = Me
        Form6.Show()
    End Sub

    Private Sub Rc4ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Rc4ToolStripMenuItem.Click
        Form7.MdiParent = Me
        Form7.Show()
    End Sub
End Class


Berikut isi daripada menunya:
Caesar Chiper





Public Class Form2

    Private Sub Form2_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 btnkeluar_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        End
    End Sub
End Class

Gronsfield Chiper

Public Class Form3

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

    Private Sub btnenkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenkript.Click
        Dim J As Integer
        Dim Jum As Integer
        Dim sKey As String
        Dim nKata As Integer
        Dim nKunci As String
        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))
        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 plaintext_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plaintext.TextChanged

    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 kunci_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kunci.TextChanged

    End Sub

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

Vernam Chiper



Public Class Form4

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

    Private Sub btnenkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenkript.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
End Class



Vigenere Chiper
Public Class Form5





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

    Private Sub btnenkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenkript.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 btnkeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnkeluar.Click
        End
    End Sub
End Class


Des Chiper

Public Class Form6
Private Sub btnenkript_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnenkript.Click
Dim kunci As String, kunciChar As String, katabaru As String
Dim Pos As Integer
Dim i As Integer, Side1 As String, Side2 As String
Dim nEnc As Integer
Pos = 1
For i = 1 To Len(Plaintext.Text)
Plaintext.Text = Mid(Plaintext.Text, i, 1)
key.Text = Mid(key.Text, Pos, 1)
Chipertext.Text = Chipertext.Text & Chr(Asc(Of Char)() Xor Asc(key.Text))
If Pos = Len(kunci) Then Pos = 0
Pos = Pos + 1
Next i
If Len(Chipertext.Text) Mod 2 = 0 Then
Side1 = StrReverse(Left(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Side2 = StrReverse(Right(Chipertext.Text, (Len(Chipertext.Text) / 2)))
Chipertext.Text = Side1 & Side2
End If
nEnc = Chipertext.Text
End Sub
Private Sub Form6_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class



RC4






Public Class Form7

  
    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plaintext.Text = ""
        kunci.Text = ""
        chipertext.Text = ""
    End Sub
    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 btnenkript.Click
        chipertext.Text = Rc4(plaintext.Text, kunci.Text)
    End Sub

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





Minggu, 02 Juni 2013

YUK! BELAJAR PEMROGRAMAN VISUAL BASIC DOT NET DI MESRAN.NET





Public Class Form1
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        rancangtabel()
  
        kb.Items.Add("TS001")
        kb.Items.Add("TS002")
        kb.Items.Add("VG001")
        kb.Items.Add("VG002")
        kb.Items.Add("KG001")
        kb.Items.Add("KG002")
    End Sub

    Sub rancangtabel()
        lv.Items.Clear()
        With lv
            .GridLines = True
            .FullRowSelect = True
            .View = View.Details
            .Columns.Add("No")
            .Columns.Add("Kode Barang", 100)
            .Columns.Add("Nama Barang", 150)
            .Columns.Add("Merek", 120)
            .Columns.Add("Harga", 130)
            .Columns.Add("Jumlah", 100)
            .Columns.Add("Total", 130)
        End With
    End Sub
    Sub addIsiTabel()
        Dim lst As New ListViewItem
        With lst
            .Text = no.Text
            .SubItems.Add(kb.Text)
            .SubItems.Add(nb.Text)
            .SubItems.Add(m.Text)
            .SubItems.Add(Harga.Text)
            .SubItems.Add(Jumlah.Text)
            .SubItems.Add(Total_harga.Text)
        End With
        lv.Items.Add(lst)
    End Sub

    Private Sub kb_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles kb.SelectedIndexChanged
        Dim x As String
        Dim a As String
        a = Microsoft.VisualBasic.Right(kb.Text, 3)
        x = Microsoft.VisualBasic.Left(kb.Text, 2)
        Select Case x
            Case "TS" : m.Text = "Toshiba"
                Select Case a
                    Case "001" : nb.Text = "Falshdisk 1GB" : Harga.Text = "10500"
                    Case "002" : nb.Text = "Flashdisk 2GB" : Harga.Text = "7500"
                End Select
            Case "VG" : m.Text = "V-Gen"
                Select Case a
                    Case "001" : nb.Text = "Falshdisk 4GB" : Harga.Text = "9000"
                    Case "002" : nb.Text = "Flashdisk 8GB" : Harga.Text = "6000"
                End Select
            Case "KG" : m.Text = "Kingston"
                Select Case a
                    Case "001" : nb.Text = "Falshdisk 12GB" : Harga.Text = "90000"
                    Case "002" : nb.Text = "Flashdisk 16GB" : Harga.Text = "120000"
                End Select
        End Select
        Jumlah.Focus()
    End Sub

    Private Sub lv_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lv.DoubleClick
        If lv.SelectedItems.Count <> 0 Then
            lv.Items.Remove(lv.SelectedItems(0))
        Else
            MsgBox("Pilih dulu list data yang dihapus")
        End If
    End Sub

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

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        lv.Items.Remove(lv.SelectedItems(0))
    End Sub

    Private Sub Jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles Jumlah.KeyPress
        Total_harga.Text = Val(Harga.Text) * Val(Jumlah.Text)
    End Sub

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

Public Class Form2

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        nama_barang.Items.Add("SONY KLD-32CX520")
        nama_barang.Items.Add("SONY KLV-40BX320")
        nama_barang.Items.Add("SONY KLV-40BX350")
        nama_barang.Items.Add("SONY KLV-40BX420")
    End Sub

    Private Sub nama_barang_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nama_barang.SelectedIndexChanged
        If nama_barang.Text = "SONY KLD-32CX520" Then
            harga.Text = 1990000
        ElseIf nama_barang.Text = "SONY KLV-40BX320" Then
            harga.Text = 590000
        ElseIf nama_barang.Text = "SONY KLV-40BX350" Then
            harga.Text = 536000
        ElseIf nama_barang.Text = "SONY KLV-40BX420" Then
            harga.Text = 910000
        End If
    End Sub

    Private Sub jumlah_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles jumlah.KeyPress
    
    End Sub

    Private Sub Proses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Proses.Click
        total_harga.Text = Val(harga.Text) * Val(jumlah.Text)
        If total_harga.Text >= 2500000 Then
            discount.Text = Val(total_harga.Text) * 0.1
            Total_pembayaran.Text = Val(total_harga.Text) - Val(discount.Text)
        Else
            discount.Text = 0
            Total_pembayaran.Text = total_harga.Text
        End If
    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

Demikianlah Postingan Saya : 
Nama :Frangky Simanjuntak
NPM:1111403