py_stepik/genb85exec.py

28 lines
687 B
Python
Raw Normal View History

2024-04-14 12:02:34 +00:00
import base64
import sys
WIDTH = 80
PREFIX = 4
def split_encoded(bytes_str: str, width: int):
for i in range(0, len(bytes_str), width):
yield bytes_str[i : i + width]
sys.stdin.reconfigure(encoding="utf-8")
code = sys.stdin.read().strip()
code = str(base64.b85encode(code.encode("utf-8")))
code = code[:-1]
print(f"{' ' * PREFIX}code = (")
first = True
for line in split_encoded(code, WIDTH - PREFIX):
if first:
print(f"{' ' * (PREFIX + 4)} {line}'")
first = False
else:
print(f"{' ' * (PREFIX + 4) } + b'{line}'")
print(f"{' ' * PREFIX})")
print(f"{' ' * PREFIX}exec(__import__('base64').b85decode(code))")