This is a proof-of-concept implementation of a lock filename generator for idlk files used by a well known desktop publishing suite.
from idlk import idlk lockname = idlk(u'My Layout File.INDD') # lockname == u'~my layout file~q7e)nv.idlk' lockname = idlk(u'My Text.icml') # lockname == u'~my text~7h5m7u.idlk'
The names of the lockfiles are derived from a given file name with the following steps:
- Apply NFC unicode normalization.
- Convert the complete filename to lower case.
- Switch to Mac Roman encoding.
- Generate a 32bit hash value over the whole file name and encode it using a custom base41 encoding scheme.
- Remove extension from the prepared file name, shorten it further to 18 characters if necessary.
- Generate the idlk file name using the following pattern: ~shortened-lowercase-basename[1..18]~hash.idlk
Note: Even though the hash-function is rather primitive, there is no way of directly deriving the original document name for a given idlk name.
The hash function is a very simple shift-add function. The only tricky/weird
thing is a final modulo with the magic number
Base41 produces a case insensitive string containing digits
a-z and the 5 additional characters
The algorithm has been deduced after observing the behavior of the original software. It currently only works with file names which are completely mappable to the Mac Roman encoding.
All code and documentation is released under the MIT license.