String plus decrypted class (vb.net Source Code)

Source: Internet
Author: User
Decryption | string ' Ez_crypt.vb (string encryption and decryption class)

' Reference namespace
Imports System
Imports Microsoft.VisualBasic
Imports System.Collections
Imports System.Configuration

Namespace Security
Public Class Crypt
' Encrypt string
Public Function Encrypt (ByVal plainstr As String, ByVal key As String) as String
Dim Strchar, Keychar, newstr as String
Dim Pos as Integer
Dim I, Intlen as Integer
Dim Side1, Side2 as String
Pos = 1

For i = 1 to Len (PLAINSTR)
Strchar = Mid (Plainstr, I, 1)
Keychar = Mid (Key, Pos, 1)
Newstr = newstr & CHR (ASC (STRCHAR) Xor ASC (Keychar))
If pos = Len (key) Then Pos = 0
pos = pos + 1
Next

If Len (newstr) Mod 2 = 0 Then
Side1 = StrReverse (left (Newstr, Len (NEWSTR)/2))
Side2 = StrReverse (Right (Newstr, Len (NEWSTR)/2))
Newstr = Side1 & Side2
End If

Encrypt = Newstr
End Function

' Decrypt string
Public Function Decrypt (ByVal plainstr As String, ByVal key As String) as String
Dim Strchar, Keychar, newstr as String
Dim Pos as Integer
Dim I as Integer
Dim Side1 as String
Dim Side2 as String
Pos = 1

If Len (plainstr) Mod 2 = 0 Then
Side1 = StrReverse (left (Plainstr, Len (PLAINSTR)/2))
Side2 = StrReverse (Right (Plainstr, Len (PLAINSTR)/2))
Plainstr = Side1 & Side2
End If

For i = 1 to Len (PLAINSTR)
Strchar = Mid (Plainstr, I, 1)
Keychar = Mid (Key, Pos, 1)
Newstr = newstr & CHR (ASC (STRCHAR) Xor ASC (Keychar))
If pos = Len (key) Then Pos = 0
pos = pos + 1
Next

Decrypt = Newstr
End Function
End Class
End Namespace

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.