2.2.5.18.4 Password Decoding
Prior to decoding, decrypt the encrypted portion of the JOINPR_USER_PASSWORD structure (section 2.2.5.17).
The implementer MUST use the following algorithm to decode the password. However, the implementer MAY use alternate data structures, so long as the result is the same.
The cleartext password represented as a Unicode string is decoded using the following sequence:
PasswordLength: The number of characters in the cleartext password.
EncodedPassword: A buffer of length JOINPR_USER_PASSWORD.Length bytes.
Seed: A single byte.
I: An unsigned integer used to index the bytes of the buffer EncodedPassword.
The buffer EncodedPassword MUST be initialized such that every bit is zero.
PasswordLength MUST be equal to (JOINPR_USER_PASSWORD.Length / 2) -1.
EncodedPassword MUST be equal to the last JOINPR_USER_PASSWORD.Length bytes of JOINPR_USER_PASSWORD.Buffer.
Seed MUST be equal to the first byte of EncodedPassword.
I MUST be JOINPR_USER_PASSWORD.Length -1.
For the initial value of I and all preceding values of I > 1, EncodedPassword[I-1] is the result of EncodedPassword[I-1] combined using a bitwise XOR operator with the result of a bitwise XOR operation of EncodedPassword[I-2] with the value of Seed.
EncodedPassword[0] is the result of 0x43 combined using a bitwise XOR operator with the value of Seed.
Then the buffer beginning at EncodedPassword[2], interpreted as an array of double byte characters, or wchar_t, is the cleartext password.