Skip to content

Instantly share code, notes, and snippets.

@tueda
Last active October 2, 2024 03:58
Show Gist options
  • Save tueda/caeadfae3308910ad5c7a8f0d9ce292f to your computer and use it in GitHub Desktop.
Save tueda/caeadfae3308910ad5c7a8f0d9ce292f to your computer and use it in GitHub Desktop.
code = """
for i in range(100):print(i%3//2*"Fizz"+i%5//4*"Buzz"or-~i)
"""

quote = '"'

import base64
import sys
import zlib

stripped = code.strip()
encoded = base64.b85encode(zlib.compress(stripped.encode())).decode()
generated = f"exec(__import__({quote}zlib{quote}).decompress(__import__({quote}base64{quote}).b85decode(b{quote}{encoded}{quote})))"
encoded = base64.b85encode(generated.encode()).decode()
generated = f"exec(__import__({quote}base64{quote}).b85decode(b{quote}{encoded}{quote}))"
print(
    f"Stat: {len(stripped)} chars -> {len(generated)} chars",
    file=sys.stderr,
    flush=True,
)
print(generated, file=sys.stderr, flush=True)
eval(generated)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment