Contoh Encrypt dan Decrypt Teks dengan Visual Basic

    Share

    eRGe@N5
    Member Newbie
    Member Newbie

    Male
    Thread & Post : 14
    Point Forum : 206733
    Thanks Given : 0
    Join date : 02.08.11
    Age : 27
    Lokasi : N3 & N5

    default Contoh Encrypt dan Decrypt Teks dengan Visual Basic

    Post by eRGe@N5 on Thu Aug 18, 2011 2:02 am

    Sintax :
    1. EncryptText(strText As String, ByVal strPwd As String) As String
    2. DecryptText(strText As String, ByVal strPwd As String)

    contoh :
    EncryptText("Uji Coba", "gila") = ž¶ªgŒ»£¨
    DecryptText("ž¶ªgŒ»£¨","gila") = Uji Coba

    Bagi sobat-sobat yang tertarik silakan ikuti langkah - langkah pembuatan fungsi Encrypt dan Decript ini


    Persiapan yang harus dilakukan
    •Buat Project Baru Standart Exe
    •3 Buah TextBox (Text1,Text2, Text3)
    •2 Buah CommandButton (Command1, Command2)
    •2 Buah Label

    •1 buat Moudule

    •Design form seperti Gambar dibawah ini
    Contoh Design Project Form Engcrypt - Descrypt



    Tempat Coding dibawah ini pada Module

    Spoiler:
    Option Explicit

    #Const CASE_SENSITIVE_PASSWORD = False

    'Encrypt text
    Public Function EncryptText(strText As String, ByVal strPwd As String) As String
    Dim i As Integer, c As Integer
    Dim strBuff As String

    #If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

    #End If

    'Encrypt string
    If Len(strPwd) Then
    For i = 1 To Len(strText)
    c = Asc(Mid$(strText, i, 1))
    c = c + Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
    strBuff = strBuff & Chr$(c And &HFF)
    Next i
    Else
    strBuff = strText
    End If
    EncryptText = strBuff
    End Function

    Public Function DecryptText(strText As String, ByVal strPwd As String)
    Dim i As Integer, c As Integer
    Dim strBuff As String

    #If Not CASE_SENSITIVE_PASSWORD Then

    'Convert password to upper case
    'if not case-sensitive
    strPwd = UCase$(strPwd)

    #End If

    'Decrypt string
    If Len(strPwd) Then
    For i = 1 To Len(strText)
    c = Asc(Mid$(strText, i, 1))
    c = c - Asc(Mid$(strPwd, (i Mod Len(strPwd)) + 1, 1))
    strBuff = strBuff & Chr$(c And &HFF)
    Next i
    Else
    strBuff = strText
    End If
    DecryptText = strBuff
    End Function


    Ketik Coding dibawah ini pada Form Project


    Spoiler:
    Option Explicit

    Private Sub Command1_Click()
    Text2 = EncryptText(Text1, "gila")
    End Sub

    Private Sub Command2_Click()
    Text3 = DecryptText(Text2, "gila")
    End Sub


    Cukup sekian dulu tutorial singkat ini, mudah-mudahan ada mamfaat nya bagi sobat - sobat VB Depeloper, selamat mencoba ... salam

      Waktu sekarang Mon Dec 05, 2016 11:28 am