lib/rubyXL/convenience_methods.rb in rubyXL-3.3.26 vs lib/rubyXL/convenience_methods.rb in rubyXL-3.3.27
- old
+ new
@@ -192,9 +192,22 @@
borders[xf.border_id] = new_border
xf.apply_border = true
register_new_xf(xf)
end
+
+ # Calculate password hash from string for use in 'password' fields.
+ # https://www.openoffice.org/sc/excelfileformat.pdf
+ def password_hash(pwd)
+ hsh = 0
+ pwd.reverse.each_char { |c|
+ hsh = hsh ^ c.ord
+ hsh = hsh << 1
+ hsh -= 0x7fff if hsh > 0x7fff
+ }
+
+ (hsh ^ pwd.length ^ 0xCE4B).to_s(16)
+ end
end
module WorksheetConvenienceMethods
NAME = 0