From 3986004f4db787aa301f520a604a317a16f46f8e Mon Sep 17 00:00:00 2001 From: owl Date: Tue, 13 May 2025 03:27:05 +0700 Subject: [PATCH] shevkan --- Dockerfile.booru-api | 11 ------- Dockerfile.vpn | 9 ------ tgbot/shit/render.py | 17 ---------- tgbot/shit/shitty_encoder.py | 61 ++++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 37 deletions(-) delete mode 100644 Dockerfile.booru-api delete mode 100644 Dockerfile.vpn create mode 100644 tgbot/shit/shitty_encoder.py diff --git a/Dockerfile.booru-api b/Dockerfile.booru-api deleted file mode 100644 index 0dbe5e6..0000000 --- a/Dockerfile.booru-api +++ /dev/null @@ -1,11 +0,0 @@ -FROM node:21 - -COPY booru-api booru-api - -WORKDIR /booru-api - -RUN npm install - -EXPOSE 3456 - -CMD ["node", "index.js"] diff --git a/Dockerfile.vpn b/Dockerfile.vpn deleted file mode 100644 index 6f0ab94..0000000 --- a/Dockerfile.vpn +++ /dev/null @@ -1,9 +0,0 @@ -FROM alpine:latest - -RUN apk add --no-cache openvpn bash iptables curl - -RUN mkdir -p /etc/openvpn - -COPY ./config.ovpn /etc/openvpn/config.ovpn - -CMD ["openvpn", "--config", "/etc/openvpn/config.ovpn"] diff --git a/tgbot/shit/render.py b/tgbot/shit/render.py index a86a57b..ee69d67 100644 --- a/tgbot/shit/render.py +++ b/tgbot/shit/render.py @@ -98,20 +98,3 @@ def image_to_string(image_file): pixel_string += " " # New line for each row return pixel_string - - -def encode_text(text: str) -> str: - binary = ''.join(format(byte, '08b') for byte in text.encode('utf-8')) - encoded = ' '.join("человек" if bit == '0' else "яйца" for bit in binary) - return encoded - - -def decode_text(encoded: str) -> str: - words = encoded.split() - binary = ''.join('0' if word == "человек" else '1' for word in words) - try: - bytes_list = [binary[i:i + 8] for i in range(0, len(binary), 8)] - decoded_bytes = bytes(int(b, 2) for b in bytes_list if len(b) == 8) - return decoded_bytes.decode('utf-8') - except (ValueError, UnicodeDecodeError): - return "Decode error :<" \ No newline at end of file diff --git a/tgbot/shit/shitty_encoder.py b/tgbot/shit/shitty_encoder.py new file mode 100644 index 0000000..2833f63 --- /dev/null +++ b/tgbot/shit/shitty_encoder.py @@ -0,0 +1,61 @@ +import enum + + +class CodingType(enum.Enum): + balls: str = "balls" + shevkan: str = "shevkan" + + +def guess_coding(text: str) -> CodingType: + + if "человек" in text: + return CodingType.balls + else: + return CodingType.shevkan + + +def encode_balls(text: str) -> str: + binary = ''.join(format(byte, '08b') for byte in text.encode('utf-8')) + encoded = ' '.join("человек" if bit == '0' else "яйца" for bit in binary) + return encoded + + +def decode_balls(encoded: str) -> str: + words = encoded.split() + binary = ''.join('0' if word == "человек" else '1' for word in words) + try: + bytes_list = [binary[i:i + 8] for i in range(0, len(binary), 8)] + decoded_bytes = bytes(int(b, 2) for b in bytes_list if len(b) == 8) + return decoded_bytes.decode('utf-8') + except (ValueError, UnicodeDecodeError): + return "Decode error :<" + + +SHEVKAN_ALPHABET = ("йов", "Шевкан", "кіть", "ош", "укладати", "зватиня", "айно", "файно") + +def to_base8_custom(num, digits=SHEVKAN_ALPHABET): + if num == 0: + return digits[0] + result = [] + while num: + result.append(digits[num % 8]) + num //= 8 + return " ".join(result[::-1]) + +def from_base8_custom(base8_str, digits=SHEVKAN_ALPHABET): + num = 0 + for char in base8_str.split(" "): + num = num * 8 + digits.index(char) + return num + +def encode_shevkan(text): + encoded = text.encode("utf-8") + num = int.from_bytes(encoded, byteorder="big") + return to_base8_custom(num) + +def decode_shevkan(base8_str): + num = from_base8_custom(base8_str.strip()) + byte_length = (num.bit_length() + 7) // 8 + bytes_data = num.to_bytes(byte_length, byteorder="big") + return bytes_data.decode("utf-8") +