/usr/lib/python2.7/dist-packages/openpyxl/utils/protection.py is in python-openpyxl 2.4.9-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | from __future__ import absolute_import
# Copyright (c) 2010-2017 openpyxl
def hash_password(plaintext_password=''):
"""
Create a password hash from a given string for protecting a worksheet
only. This will not work for encrypting a workbook.
This method is based on the algorithm provided by
Daniel Rentz of OpenOffice and the PEAR package
Spreadsheet_Excel_Writer by Xavier Noguer <xnoguer@rezebra.com>.
See also http://blogs.msdn.com/b/ericwhite/archive/2008/02/23/the-legacy-hashing-algorithm-in-open-xml.aspx
"""
password = 0x0000
for idx, char in enumerate(plaintext_password, 1):
value = ord(char) << idx
rotated_bits = value >> 15
value &= 0x7fff
password ^= (value | rotated_bits)
password ^= len(plaintext_password)
password ^= 0xCE4B
return str(hex(password)).upper()[2:]
|