Simple and Easy-to-use VB string encryption and decryption functions

Source: Internet
Author: User

Private function encrypt (byval strsource as string) as string 'encryption
Dim blowdata as byte
Dim bhigdata as byte
Dim I as long
Dim K as integer
Dim strencrypt as string
Dim strchar as string
Dim keytemp as string
Dim key1 as byte

For k = 1 to 30
Keytemp = keytemp & CSTR (INT (RND * (9) + 1 ))
Next

Key1 = cbyte (mid (keytemp, 11, 1) & Mid (keytemp, 27, 1 ))
For I = 1 to Len (strsource)
Strchar = mid (strsource, I, 1) 'removes a character from the string to be encrypted
Blowdata = ASCB (midb (strchar, 1, 1) XOR key1' obtains the lower byte of the character and key1 for exclusive or operation.
Shigdata = ASCB (midb (strchar, 2, 1) 'takes the high byte of the character
Strencrypt = strencrypt & chrb (blowdata) & chrb (bhigdata) 'combines the computed data into new characters
Next I
Encrypt = keytemp & strencrypt

End Function

 

Private function decrypt (byval strsource as string) as string 'decryption
Dim blowdata as byte
Dim bhigdata as byte
Dim I as long
Dim K as integer
Dim strdecrypt as string
Dim strchar as string
Dim keytemp as string

Dim key1 as byte
Keytemp = mid (strsource, 1, 30)

Key1 = cbyte (mid (keytemp, 11, 1) & Mid (keytemp, 27, 1 ))
For I = 31 to Len (strsource)
Strchar = mid (strsource, I, 1) 'removes a character from the string to be decrypted
Blowdata = ASCB (midb (strchar, 1, 1) XOR key1' obtains the lower byte of the character and key1 for exclusive or operation.
Bhigdata = ASCB (midb (strchar, 2, 1) 'takes the high byte of the character
Strdecrypt = strdecrypt & chrb (blowdata) & chrb (bhigdata) 'combines the computed data into new characters
Next I
Decrypt = strdecrypt

End Function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.