Skip to content

Instantly share code, notes, and snippets.

@danila-schelkov
Last active April 17, 2022 11:22
Show Gist options
  • Save danila-schelkov/51f29741444e9948accb615676f1115a to your computer and use it in GitHub Desktop.
Save danila-schelkov/51f29741444e9948accb615676f1115a to your computer and use it in GitHub Desktop.
TAG_ALPHABET = '0289PYLQGRJCUV'
def get_id(_tag):
tag_chars = list(_tag.upper())
result = 0
for char in tag_chars:
if not char in TAG_ALPHABET:
continue
result *= len(TAG_ALPHABET)
result += TAG_ALPHABET.index(char)
high_id = result % 256
return (high_id, (result - high_id) >> 8)
def get_tag(high_id, low_id):
_id = low_id * 256 + high_id
_tag = ''
while _id > 0:
char_index = _id % len(TAG_ALPHABET)
_tag = TAG_ALPHABET[char_index] + _tag
_id -= char_index
_id //= len(TAG_ALPHABET)
return _tag
if __name__ == '__main__':
# tag = input('Enter the tag: ')
# if tag[0] == '#':
# tag = tag[1:]
tag = '2pp'
print(get_id(tag))
print(get_tag(0, 1))
print(get_tag(3, 100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment