gpt4 book ai didi

vba - 为什么此代码会禁用工作表保护?

转载 作者:行者123 更新时间:2023-12-04 21:32:15 26 4
gpt4 key购买 nike

以下代码由 this website 提供我用它来取消保护我不知道密码的工作表。

Sub DisableSheetProtection()
Dim password As String
On Error Resume Next
For i = 65 To 66: For j = 65 To 66
For k = 65 To 66: For l = 65 To 66
For m = 65 To 66: For n = 65 To 66
For o = 65 To 66: For p = 65 To 66
For q = 65 To 66: For r = 65 To 66
For S = 65 To 66: For t = 32 To 126
ActiveSheet.Unprotect Chr(i) & _
Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(n) & Chr(o) & _
Chr(p) & Chr(q) & Chr(r) & _
Chr(S) & Chr(t)

Next t: Next S: Next r: Next q
Next p: Next o: Next n: Next m
Next l: Next k: Next j: Next i
MsgBox "Sheet protection disabled."
End Sub

问题是: 它是如何或为什么起作用的? Chr(65) 是 A,Chr(66) 是 B,Chr(32) 到 Chr(126) 是整个字母表和特殊字符。

基本上,如果您想尝试所有可能性,则需要这样做:
Sub DisableSheetProtection()
Dim password As String
On Error Resume Next
For i = 32 To 126: For j = 32 To 126
For k = 32 To 126: For l = 32 To 126
For m = 32 To 126: For n = 32 To 126
For o = 32 To 126: For p = 32 To 126
For q = 32 To 126: For r = 32 To 126
For S = 32 To 126: For t = 32 To 126
ActiveSheet.Unprotect Chr(i) & _
Chr(j) & Chr(k) & Chr(l) & _
Chr(m) & Chr(n) & Chr(o) & _
Chr(p) & Chr(q) & Chr(r) & _
Chr(S) & Chr(t)

Next t: Next S: Next r: Next q
Next p: Next o: Next n: Next m
Next l: Next k: Next j: Next i
MsgBox "Sheet protection disabled."
End Sub

但是该代码可以正常工作,因为它用于取消保护并且您无法打印出正确的密码。我认为这与 VBA 取消保护/保护方法有关。

最佳答案

Internal XL passwords are about as useful for security as tissuepaper. The reason is that the passwords you enter (i.e., withTools/Protect/Protect Worksheet or /Protect Workbook) are not useddirectly in protection.Instead they are hashed (mathematicallytransformed) into a much less secure code. Effectively, any passwordof any length is transformed into a string of 12 characters, the first11 of which have one of only two possible values. The remainingcharacter can have up to 95 possible values, leading to only

2^11 * 95 = 194,560 potential passwords.

This may seem like a lot, but it only takes a few seconds for a modern computer >to try them all. As a comparison, a 4-character password containing just the 26lower case alphabet characters has 456,976 combinations, and a3-character password consisting of lower case, upper case and thedigits 0-9 will have 238,328 combinations.

Again, it doesn't matter what your original password is, one of those194K strings will unlock your sheet or workbook.


更多阅读 this

关于vba - 为什么此代码会禁用工作表保护?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49236723/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com