Sha256: 0b3cab6aa91ee972ab17b90b65b93e9fba90db8b3d44e0f1253ea59436af0e95

Contents?: true

Size: 468 Bytes

Versions: 65

Compression:

Stored size: 468 Bytes

Contents

module Spreadsheet
  module Excel
module Password
  class <<self
    ##
    # Makes an excel-compatible hash
    def password_hash(password)
      hash = 0
      password.chars.reverse_each { |chr| hash = rol15(hash ^ chr[0].ord) }
      hash ^ password.size ^ 0xCE4B
    end

    private
    ##
    # rotates hash 1 bit left, using lower 15 bits
    def rol15(hash)
      new_hash = hash << 1
      (new_hash & 0x7FFF) | (new_hash >> 15)
    end
  end

end
  end
end

Version data entries

65 entries across 65 versions & 3 rubygems

Version Path
spreadsheet-0.7.5 lib/spreadsheet/excel/password_hash.rb
spreadsheet-0.7.4 lib/spreadsheet/excel/password_hash.rb
spreadsheet-0.7.3 lib/spreadsheet/excel/password_hash.rb
spreadsheet-0.7.2 lib/spreadsheet/excel/password_hash.rb
spreadsheet-0.7.1 lib/spreadsheet/excel/password_hash.rb