bot/utils/convert.py
2026-08-31 23:45:03 +03:00

14 lines
554 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

TABLE = 'ёйцукенгшщзхъфывапролджэячсмитьбюЁЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ1234567890-_. '
NUMBER = lambda n: str(n) if n > 9 else '0'+str(n)
def encode(text: str) -> str:
return ''.join([
NUMBER(TABLE.index(char)) if char in TABLE else char
for char in text
])
def decode(text: str) -> str:
return ''.join([
TABLE[int(text[index:index+2])] if text[index:index+2].isdigit() else text[index:index+2]
for index in range(0, len(text), 2)
])