Class: PasswordRecord
- Inherits:
-
BiffRecord
- Object
- BiffRecord
- PasswordRecord
- Defined in:
- lib/surpass/biff_record.rb
Overview
This record is part of the worksheet/workbook protection. It stores a 16-bit hash value, calculated from the worksheet or workbook protection password.
Constant Summary collapse
- RECORD_ID =
0x0013
Constants inherited from BiffRecord
BiffRecord::BIFF_LIMIT, BiffRecord::CONTINUE_RECORD_ID
Instance Attribute Summary
Attributes inherited from BiffRecord
Instance Method Summary collapse
-
#initialize(password = "") ⇒ PasswordRecord
constructor
A new instance of PasswordRecord.
-
#password_hash(plaintext) ⇒ Object
Based on the algorithm provided by Daniel Rentz of OpenOffice.
Methods inherited from BiffRecord
Constructor Details
#initialize(password = "") ⇒ PasswordRecord
Returns a new instance of PasswordRecord.
292 293 294 |
# File 'lib/surpass/biff_record.rb', line 292 def initialize(password = "") @record_data = [password_hash(password)].pack('v') end |
Instance Method Details
#password_hash(plaintext) ⇒ Object
Based on the algorithm provided by Daniel Rentz of OpenOffice.
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/surpass/biff_record.rb', line 297 def password_hash(plaintext) return 0 if plaintext === "" hash = 0x0000 plaintext.unpack('C*').each_with_index do |t, i| c = t << (i + 1) low_15 = c & 0x7fff high_15 = c & 0x7fff << 15 high_15 = high_15 >> 15 c = low_15 | high_15 hash = (hash ^ c) end hash = (hash ^ plaintext.length) hash = (hash ^ 0xCE4B) hash end |