Contoh Encrypt dan Decrypt Teks dengan Visual Basic 6.0
Tujuan Utama Encrypt dan Descript teks adalah untuk merubah karakter teks sehingga tidak mudah dibaca atau dipahami orang lain, metode ini banyak dipakai untuk proteksi seperti dunia Internet, Bank baik proteksi password, pengiriman pesan, pengiriman data dan lain-lain. Disini saya memberikan contoh dasar bagaimana pembuatan Encrypt dan Descript teks tersebut dengan Visual Basic
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
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
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 ...
Semoga Bermanfaat
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
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
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 ...
Semoga Bermanfaat
Posting Komentar untuk "Contoh Encrypt dan Decrypt Teks dengan Visual Basic 6.0"