Encrypt & Decrypt Text with VB

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, pengirimandata 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 … salam🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s