Skip to content

Instantly share code, notes, and snippets.

@nk0t
Created July 13, 2014 12:12
Show Gist options
  • Save nk0t/06a9212c9c4b2a482c1c to your computer and use it in GitHub Desktop.
Save nk0t/06a9212c9c4b2a482c1c to your computer and use it in GitHub Desktop.
import sys
"""
_ = 1
__ = 2
___ = 4
____ = 8
_____ = 16
______ = 32
_______ = 64
"""
def pack(s):
code = '_=()==();__=_+_;___=__+__;____=___+___;_____=____+____;______=_____+_____;_______=______+______;'
r = []
for c in s:
n = ord(c)
r.append('+'.join(['_'*(i+1) for i in range(7) if n&(1<<i)]))
p = ','.join(r)
code += 'exec("%c"*{})%({})'.format(len(s),p)
print code
def main():
if len(sys.argv) > 1:
f = open(sys.argv[1])
pack(f.read())
f.close()
else:
print 'usage: pypack.py file'
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment