excel - 使用 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
解决方案
推荐阅读
- javascript - 如何为 v-for 循环中的项目应用特定的 CSS?
- python - CSV Writer 双引号
- reactjs - 为什么 React 路由器中的组件没有接收到我的道具
- python - 如何修复“/bin/sh: bc: command not found”
- php - Laravel ORM:不带表前缀的查询
- python - 由对等方为 getstream.io python 客户端重置连接
- c# - 无法在asp.net的sql数据库中添加数据
- javascript - 只允许将事件拖到后台事件上
- php - 测试驱动开发和 KISS
- python - 我在 Python 中的 If 语句不起作用