encryption.bas

来自「transport system for managing transport 」· BAS 代码 · 共 48 行

BAS
48
字号
Attribute VB_Name = "Encryption"
Option Explicit
Public Function Encrypt(Key1 As String, txtcode As String)
Dim i, j, k As Integer, thekey
Dim a, b, CryptText As String
On Error Resume Next
    If Key1 <> "" Then
        thekey = Key1
        i = 0
        For j = 1 To Len(txtcode)
            i = i + 1
            If i > Len(thekey) Then i = 1
            a = Mid(txtcode, j, 1)
            k = Asc(a)
            b = Mid(thekey, i, 1)
            k = k + Asc(b)
            If k > 255 Then k = k - 255
            CryptText = CryptText & Chr(k)
        Next j
        txtcode = CryptText
Encrypt = txtcode
End If
End Function
Public Function Decrypt(Key1 As String, txtcode As String)
Dim i, j, k As Integer, thekey
Dim a, b, CryptText As String
On Error Resume Next
    CryptText = ""
    If Key1 <> "" Then
        thekey = Key1
        i = 0
        For j = 1 To Len(txtcode)
            i = i + 1
            If i > Len(thekey) Then i = 1
            a = Mid(txtcode, j, 1)
            k = Asc(a)
            b = Mid(thekey, i, 1)
            k = k - Asc(b)
            If k < 0 Then k = k + 255
            CryptText = CryptText & Chr(k)
        Next j
     txtcode = CryptText
     Decrypt = txtcode
    End If
End Function


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?