Saturday, 29 June 2013

Program Citra


1.caesar





Public Class Caesar

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.Click
        Dim x As String
        Dim bil As Integer
        Chiperteks.Text = ""
        For i = 1 To Len(Plainteks.Text)
            x = Microsoft.VisualBasic.Mid(Plainteks.Text, i, 1)
            bil = Asc(x)
            bil = bil + 3 Mod 26
            x = Chr(bil)
            Chiperteks.Text = Chiperteks.Text & x
        Next

    End Sub

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

    Private Sub BtnDes_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDes.Click
        Dim x As String
        Dim bil As Integer
        Chiperteks.Text = ""
        For i = 1 To Len(Plainteks.Text)
            x = Microsoft.VisualBasic.Mid(Plainteks.Text, i, 1)
            bil = Asc(x)
            bil = bil - 3 Mod 26
            x = Chr(bil)
            Chiperteks.Text = Chiperteks.Text & x
        Next
    End Sub
End Class

2.gronsfeld



Public Class Gronsfeld

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.Click
        Dim x As String
        Dim CI As Integer
        chiperteks.Text = ""
        For i = 1 To Len(plainteks.Text)
            x = Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
            CI = Asc(x)
            CI = (plainteks.Text + kunci.Text) Mod 26
            x = Chr(CI)
            chiperteks.Text = chiperteks.Text & x
        Next
        chiperteks.Text = enkripsi(plainteks.Text, kunci.Text)
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnDeskripsi.Click

        Dim x As String
        Dim CI As Integer
        Dim KI As Integer
        Dim PI As Integer
        chiperteks.Text = ""
        For i = 1 To Len(plainteks.Text)
            x = Microsoft.VisualBasic.Mid(plainteks.Text, i, 1)
            PI = Asc(x)
            PI = (CI - KI) Mod 26
            x = Chr(PI)
            chiperteks.Text = chiperteks.Text & x
        Next
    End Sub
    Function enkripsi(ByVal teks As String, ByVal kunci As String) As String
        Dim a As Integer
        Dim b 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
        a = 0
        b = Len(teks)
        sPlain = ""
        sKey = kunci
        sKata = teks
        For i = 1 To b
            If a = Len(sKey) Then
                a = 1
            Else
                a = a + 1
            End If
            nKata = Asc(Mid(sKata, i, 1))
            nKunci = Asc(Mid(sKey, a, 1))
            nEnc = ((nKata + nKunci) Mod 26)
            sPlain = sPlain & Chr((nEnc))
        Next i
        enkripsi = sPlain
    End Function

    Private Sub Gronsfeld_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        chiperteks.Text = ""
        plainteks.Text = ""
        kunci.Text = ""
    End Sub
End Class

3.vernam



Public Class vernam
    Private Sub vernam_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        plainteks.Text = ""
        kunci.Text = ""
        chiperteks.Text = ""

    End Sub

    Private Sub BtnEn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnEn.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 = plainteks.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
        chiperteks.Text = sPlain

    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 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
End Class

4.vigenere



Public Class Form1

    Private Sub BtnProses_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnProses.Click
        Chiperteks.Text = Enkripsi(Plainteks.Text, Kunci.Text)
    End Sub
    Function enkripsi(ByVal teks As String, ByVal kunci As String) As String
        Dim a As Integer
        Dim b 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
        a = 0
        b = Len(teks)
        sPlain = ""
        sKey = kunci
        sKata = teks
        For i = 1 To b
            If a = Len(sKey) Then
                a = 1
            Else
                a = a + 1
            End If
            nKata = Asc(Mid(sKata, i, 1))
            nKunci = Asc(Mid(sKey, a, 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
        Plainteks.Text = ""
        Chiperteks.Text = ""
        Kunci.Text = ""
    End Sub

    Private Sub BtnKeluar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnKeluar.Click
        Close()
    End Sub
End Class



Monday, 10 June 2013

Pengolahan Citra Untuk Memberi Efek Gambar

Desain Program

Listin Program

Public Class Form2
    Dim gambar As Bitmap
    Private Sub OpenCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenCitraToolStripMenuItem.Click
        OFD.Filter = "BMP|*.bmp|JPG|*.jpg"
        OFD.ShowDialog()
        If OFD.FileName = "" Then Exit Sub
        PictureBox1.Image = Image.FromFile(OFD.FileName)
        gambar = New Bitmap(PictureBox1.Image)
    End Sub

    Private Sub SaveCitraToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveCitraToolStripMenuItem.Click
        SFD.Filter = "JPG|*.jpg|BMP|*.bmp"
        SFD.ShowDialog()

        If SFD.FileName = "" Then Exit Sub

        If SFD.FilterIndex = 1 Then
            gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
        End If
        If SFD.FilterIndex = 2 Then
            gambar.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Bmp)
        End If
    End Sub

    Private Sub GrayscaleToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GrayscaleToolStripMenuItem.Click
        Dim pb, pc As Integer
        Dim rt, vm, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .GetPixel(pc, pb).B
                    rt = (vm + vh + vb) / 3
                    .SetPixel(pc, pb, Color.FromArgb(rt, rt, rt))
                Next
                PictureBox2.Image = gambar
                PictureBox2.Refresh()
            Next
        End With
    End Sub

    Private Sub NegatifToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NegatifToolStripMenuItem.Click
        Dim pb, pc As Integer
        Dim vm, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = 255 - .GetPixel(pc, pb).R
                    vb = 255 - .GetPixel(pc, pb).G
                    vh = 255 - .GetPixel(pc, pb).B
                    If vm <= 0 Then vm = 0
                    If vb <= 0 Then vb = 0
                    If vh <= 0 Then vh = 0
                    .SetPixel(pc, pb, Color.FromArgb(vm, vb, vh))
                Next
                PictureBox2.Image = gambar
                PictureBox2.Refresh()
            Next
        End With
       
    End Sub

    Private Sub BrigthnessToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BrigthnessToolStripMenuItem.Click
        Dim pb, pc As Integer
        Dim vm, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R + 5
                    vb = .GetPixel(pc, pb).G + 5
                    vh = .GetPixel(pc, pb).B + 5
                    If vm > 255 Then vm = 255
                    If vb > 255 Then vb = 255
                    If vh > 255 Then vh = 255
                    .SetPixel(pc, pb, Color.FromArgb(vm, vb, vh))
                Next
                PictureBox2.Image = gambar

                PictureBox2.Refresh()
            Next
        End With
    End Sub

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

    Private Sub BinerToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BinerToolStripMenuItem.Click
        Dim pb, pc As Integer
        Dim rata, vm, vb, vh As Double
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .GetPixel(pc, pb).B
                    rata = (vm + vh + vb) / 3

                    If (rata < 128) Then
                        vm = 0
                        vh = 0
                        vb = 0
                    Else
                        vm = 255
                        vh = 255
                        vb = 255
                    End If
                    .SetPixel(pc, pb, Color.FromArgb(vm, vb, vh))
                Next
                PictureBox2.Image = gambar
                PictureBox2.Refresh()
            Next
        End With
    End Sub

    Private Sub RotateToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RotateToolStripMenuItem.Click
        Dim pb, pc As Integer
        Dim vm, vb, vh As Double
        Dim gambar3 As Bitmap = New Bitmap(PictureBox1.Image)
        With gambar
            For pb = 0 To .Height - 1
                For pc = 0 To .Width - 1
                    vm = .GetPixel(pc, pb).R
                    vb = .GetPixel(pc, pb).G
                    vh = .GetPixel(pc, pb).B
                   
                    gambar3.SetPixel(.Width - 1 - pc, .Height - 1 - pb, Color.FromArgb(vh, vm, vb))
                Next
                PictureBox2.Image = gambar
                PictureBox2.Refresh()
            Next
        End With
        gambar = gambar3
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        gambar = New Bitmap(PictureBox1.Image)
    End Sub

End Class

Semoga Bermanfaat.....google,com