Fascinating - I used to know a code snippet, but not the explanation Brettj wrote. As others have explained, this is a search for brute force for hash collisions. In fact, it seems that this was done by trial and error, as it does a lot more work than necessary (194560 combinations were generated, but there are only 32768 hash values).
Short Excel hashing algorithm (as described in http://chicago.sourceforge.net/devel/docs/excel/encrypt.html ):
- Take the ascii code of each passwort character.
- Treat it like a 16-bit number. Move its bits to the left, depending on the position of the character (1 bit for the first character, 2 for the second, etc.).
- XOR all characters together, giving a 16-bit signed int> = 0.
- XORs that result in password length and magic number.
Knowing this, you can begin the search for brute force as follows:
- The most significant bit is always zero, so 15 bits are required for testing.
- Divide them into three counters, each of which covers 5 bits. Thus, each counter can represent a printed ascii char.
- Set the ascii representation of these counters to a password string so that they do not affect each other.
The easiest way is to use an 11-digit password and place the counters in positions 1, 6 and 11. Switching the bits in step 2 aligns the counter bit in the right direction: the first counter ("x") is shifted 1 bit, the second ("y") is 6 bits, the third ("z") is 11 bits. In the bitwise hash representation, counters affect the following bits:
bit: 76543210 76543210 cnt: -zzzzyyy yyxxxxxz
XOR operations can be ignored because the XOR argument is constantly constant. For the same reason, you can add a constant offset (for example, 64). It also does not matter which character is used for other password bytes (2-5, 7-10).
Repeating all possible combinations of x, y, z, you will eventually find a password that gives the same hash value as the original one.
Public Sub demo() ' http://stackoverflow.com/questions/12852095/how-does-excels-worksheet-password-protection-work Dim x As Integer, y as Integer, z as Integer Dim part1 As String, part12 As String Dim sh As Worksheet Set sh = ThisWorkbook.Worksheets(1) sh.Protect "$ome_Insanely_Long_and_c0mplex_password! [(which i$ imp*ssible t0 re-member)]" For x = 64 To 95 ' pad with dots, so that x, y and z affect nonoverlapping bits of the hash. part1 = Chr(x) + "...." For y = 64 To 95 part12 = part1 + Chr(y) + "...." For z = 64 To 95 On Error Resume Next sh.Unprotect part12 + Chr(z) If Err.Number = 0 Then Debug.Print "Password: '" & part12 + Chr(z) & "'" Exit Sub End If On Error GoTo 0 Next Next Next End Sub
Torben klein
source share