module Spreadsheet::Excel::Password

Public Class Methods

password_hash(password) click to toggle source

Makes an excel-compatible hash

# File lib/spreadsheet/excel/password_hash.rb, line 7
def password_hash(password)
  hash = 0
  password.chars.reverse_each { |chr| hash = rol15(hash ^ chr[0].ord) }
  hash ^ password.size ^ 0xCE4B
end

Private Class Methods

rol15(hash) click to toggle source

rotates hash 1 bit left, using lower 15 bits

# File lib/spreadsheet/excel/password_hash.rb, line 16
def rol15(hash)
  new_hash = hash << 1
  (new_hash & 0x7FFF) | (new_hash >> 15)
end