07.05.2014 Views

The Microsoft Excel File Format - OpenOffice.org

The Microsoft Excel File Format - OpenOffice.org

The Microsoft Excel File Format - OpenOffice.org

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

4.19 <strong>File</strong> Protection<br />

• BIFF2-BIFF5 Stream Encryption<br />

To encrypt record data, a 128-bit sized key sequence is used, which has been generated from a password before (see<br />

above). All stream data is encrypted in blocks of 16 bytes using the key sequence. In every data block, each byte is<br />

encoded using the corresponding byte of the key sequence. <strong>The</strong> offset pointer into the key sequence is reinitialised<br />

whenever a new record is started. <strong>The</strong> initial value of this offset is dependent on the stream position and size of the new<br />

record (it does not simply restart at 0). For details see the following algorithm.<br />

<strong>The</strong> following pseudo-code algorithm shows how to encrypt the data of an entire record (assuming that stream points to<br />

the start of the record data):<br />

ALGORITHM Write_Record_XOR( stream, record_data[], record_size, key_seq[]<br />

)<br />

1) key_index ← ((position of stream) + record_size) AND 0F H<br />

2) record_index ← 0<br />

3) IF record_index = record_size THEN RETURN<br />

4) data_byte = record_data[record_index] XOR key_seq[key_index]<br />

5) rotate all 8 bits of data_byte right by 3 bits<br />

6) write data_byte to stream<br />

7) key_index ← (key_index + 1) AND 0F H {rotate inside key_seq[]}<br />

8) record_index ← record_index + 1<br />

9) JUMP 3)<br />

• BIFF2-BIFF5 Stream Decryption<br />

To decrypt record data, a 128-bit sized key sequence is used, which has been generated from a password before (see<br />

above). Decryption works similar to encryption (see above), but in reversed order of operations.<br />

<strong>The</strong> following pseudo-code algorithm shows how to decrypt the data of an entire record (assuming that stream points to<br />

the start of the record data):<br />

ALGORITHM Read_Record_XOR( stream, record_size, key_seq[] )<br />

1) key_index ← ((position of stream) + record_size) AND 0F H<br />

2) create a sequence record_data[] containing record_size bytes<br />

3) record_index ← 0<br />

4) IF record_index = record_size THEN RETURN record_data[]<br />

5) data_byte ← read 1 byte from stream<br />

6) rotate all 8 bits of data_byte left by 3 bits<br />

7) record_data[record_index] ← data_byte XOR key_seq[key_index]<br />

8) key_index ← (key_index + 1) AND 0F H {rotate inside key_seq[]}<br />

9) record_index ← record_index + 1<br />

10) JUMP 4)<br />

119

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!