首页 > 解决方案 > 使用 Xor 运算符对继承代码的反馈

问题描述

我对 VBA 很陌生,并且继承了 VBA 代码,编写此代码的人使用下面的子和函数保护了工作表。

有人能解码下面的吗?似乎他正在使用特殊字符,但这段代码对于我目前的理解来说太高级了。

任何指导或反馈将不胜感激。

Public Sub makeSafe(ws As Worksheet, safe As Boolean)

    If safe Then
        If Not ws.Name = "COMPLETED" Then
            ws.Columns("A:B").Locked = False
            ws.Columns("D").Locked = False
        End If
        ws.Protect XOREnc("½ ·Î½ ·", "nope")
    Else
        ws.Unprotect XOREnc("½ ·Î½ ·", "nope")
    End If

End Sub

Function XOREnc(theInput As String, theKey As String) As String

    Dim val1, val2 As Integer, out As String, temp As Integer

    For i = 1 To Len(theInput)
        val1 = Asc(Mid(theInput, i, 1))
        val2 = Asc(Mid(theKey, i Mod Len(theKey) + 1, 1))
        If val1 Xor val2 < 32 Then
            temp = 255 - (val1 Xor val2)
        Else
            temp = val1 Xor val2
        End If
        out = out & Chr(temp)
     Next i
     XOREnc = out
End Function

标签: excelvbaxor

解决方案


推荐阅读