import sys

def qhash (inputstr):
    instr = ""
    if isinstance (inputstr, str):
        instr = inputstr
    elif isinstance (inputstr, unicode):
        instr = inputstr.encode ("utf8")
    else:
        return -1

    h = 0x00000000
    for i in range (0, len (instr)):
        h = (h << 4) + ord(instr[i])
        h ^= (h & 0xf0000000) >> 23
        h &= 0x0fffffff

    return h


ImageId = sys.argv[1]
print(ImageId)
print(len("file____mnt_onboard_Imports_Brandon_Sanderson_Shadows_Of_Self_-_Brandon_Sanderson_epub"))

hash1 = qhash(ImageId)
print(hash1)
print("_test_covers - hash1='%s'" % (hash1))
xff   = 0xff
dir1  = hash1 & xff
dir1  &= 0xff
print("_test_covers - dir1='%s', xff='%s'" % (dir1, xff))
xff00 = 0xff00
dir2  = (hash1 & xff00) >> 8
print("_test_covers - hash1='%s', dir1='%s', dir2='%s'" % (hash1, dir1, dir2))

with open("output.ini", "a") as f:
  print("[Sub Folders]", file=f)
  print(f"dir1={dir1}", file=f)
  print(f"dir2={dir2}", file=f)
