man balls man balls man balls
This commit is contained in:
parent
339ebff931
commit
ec664162f6
2 changed files with 28 additions and 1 deletions
|
@ -98,3 +98,20 @@ 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 :<"
|
Loading…
Add table
Add a link
Reference in a new issue