Skip to content

Instantly share code, notes, and snippets.

@cymerrad
Created April 11, 2019 17:49
Show Gist options
  • Save cymerrad/719e83c8a859f4449c6870fc8a56b6ef to your computer and use it in GitHub Desktop.
Save cymerrad/719e83c8a859f4449c6870fc8a56b6ef to your computer and use it in GitHub Desktop.
def calculate_polish_hash(b_number):
polish_template = "PLkk bbbs sssx cccc cccc cccc cccc"
if b_number[:2] != "PL":
b_number = "PL" + b_number # prefix
assert len(b_number.replace(" ", "")) == len(polish_template.replace(" ", ""))
b_number = b_number.replace(" ", "")
rearranged = b_number[4:] + b_number[:2] + "00"
converted = "".join([str(int(x, 36)) for x in rearranged])
remainder = int(converted) % 97
result = (98 - remainder)
return str(result) if result > 9 else "0" + str(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment