The Microsoft Excel File Format - OpenOffice.org
The Microsoft Excel File Format - OpenOffice.org
The Microsoft Excel File Format - OpenOffice.org
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
4 Worksheet/Workbook Stream<br />
• BIFF2-BIFF5 Encryption Key<br />
<strong>The</strong> 16-bit encryption key is used for the BIFF2-BIFF5 XOR stream encryption algorithm (➜4.19.1). It is calculated<br />
from the password. <strong>The</strong> FILEPASS record stores this key and the hash value (➜4.18.4) of the password (the hash value<br />
is not used to encrypt the data). <strong>The</strong> length of the password is restricted to 15 characters.<br />
<strong>The</strong> following pseudo-code algorithm shows how to create the encryption key from a given byte-string password:<br />
ALGORITHM Get_Encryption_Key_XOR( password )<br />
1) key ← 0 ; key_base ← 8000 H ; key_final ← FFFF H ; char_index ← 0<br />
2) char_count ← character count of password<br />
3) char ← character from password with index char_index {right-to-left, 0 is rightmost}<br />
4) char ← char AND 7F H {use only the lower 7 bits of each character}<br />
5) bit_index ← 0<br />
6) rotate the lower 16 bits of key_base left by 1 bit<br />
7) IF (least significant bit of key_base) = 1 THEN key_base ← key_base XOR 1020 H<br />
8) rotate the lower 16 bits of key_final left by 1 bit<br />
9) IF (least significant bit of key_final) = 1 THEN key_final ← key_final XOR 1020 H<br />
10) IF (bit with index bit_index in char) = 1 THEN key ← key XOR key_base<br />
11) bit_index ← bit_index + 1<br />
12) IF bit_index < 8 THEN JUMP 6)<br />
13) char_index ← char_index + 1<br />
14) IF char_index < char_count THEN JUMP 3)<br />
15) RETURN key XOR key_final<br />
• BIFF2-BIFF5 Encryption Key Sequence<br />
<strong>The</strong> encryption sequence is needed to encrypt or decrypt the record contents. It is generated from the password and the<br />
encryption key (which is generated from the password too, see above). <strong>The</strong> size of the encryption key sequence is always<br />
128 bit.<br />
<strong>The</strong> following pseudo-code algorithm shows how to create the encryption key from a given byte-string password (and the<br />
encryption key “key”):<br />
ALGORITHM Get_Key_Sequence_XOR( password, key )<br />
1) char_count ← character count of password<br />
2) create a sequence key_seq[] containing 16 bytes<br />
3) fill the first char_count bytes of key_seq[] with all characters of password<br />
4) fill the remaining (16 – char_count) bytes of key_seq[] with the first bytes of the sequence<br />
{ BB H ,FF H ,FF H ,BA H ,FF H ,FF H ,B9 H ,80 H ,00 H ,BE H ,0F H ,00 H ,BF H ,0F H ,00 H }<br />
5) key_lower ← lower 8 bits of key ; key_upper ← upper 8 bits of key<br />
6) seq_index ← 0<br />
7) key_seq[seq_index] ← key_seq[seq_index] XOR key_lower<br />
8) key_seq[seq_index + 1] ← key_seq[seq_index + 1] XOR key_upper<br />
9) seq_index ← seq_index + 2<br />
10) IF seq_index < 16 THEN JUMP 7)<br />
11) rotate all bytes of key_seq left by 2 bits<br />
12) RETURN key_seq[]<br />
118