Skip to content

Instantly share code, notes, and snippets.

@MatthewScholefield
Created September 19, 2019 23:20
Show Gist options
  • Save MatthewScholefield/653543360d2a2bd8f9a7533088a0ffff to your computer and use it in GitHub Desktop.
Save MatthewScholefield/653543360d2a2bd8f9a7533088a0ffff to your computer and use it in GitHub Desktop.
Store and run Python source encoded in a massive integer
obfuscate = lambda code: int(''.join(['{:08b}'.format(i) for i in list(bytes(code.encode()))]), 2)
run = lambda x: exec(bytes([int('{:b}'.format(x)[max(0, i - 8):i], 2) for i in range(len('{:b}'.format(x)) % 8, len('{:b}'.format(x)) + 1, 8) if i > 0]))
a = obfuscate("print('hello')")
b = a * 12
# run(b) # Will error out
run(b / 12) # Prints "hello"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment