読者です 読者をやめる 読者になる 読者になる

pythonで難読化するやつ

execさえなんとかなれば記号だけでもプログラミングできそう

pypack.py

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()

fizzbuzz.py

for i in range(1,100):
    if i%15 == 0:
        print 'FizzBuzz'
    elif i%3 == 0:
        print 'Fizz'
    elif i%5 == 0:
        print 'Buzz'
    else:
        print i

fizzbuzz_packed.py

_=()==();__=_+_;___=__+__;____=___+___;_____=____+____;______=_____+_____;_______=______+______;exec("%c"*171)%(__+___+______+_______,_+__+___+____+______+_______,__+_____+______+_______,______,_+____+______+_______,______,_+____+______+_______,__+___+____+______+_______,______,__+_____+______+_______,_+______+_______,__+___+____+______+_______,_+__+___+______+_______,_+___+______+_______,____+______,_+_____+______,___+____+______,_+_____+______,_____+______,_____+______,_+____+______,__+____+_____+______,__+____,______,______,______,______,_+____+______+_______,__+___+______+_______,______,_+____+______+_______,_+___+______,_+_____+______,_+___+_____+______,______,_+___+____+_____+______,_+___+____+_____+______,______,_____+______,__+____+_____+______,__+____,______,______,______,______,______,______,______,______,_____+______+_______,__+_____+______+_______,_+____+______+_______,__+___+____+______+_______,___+_____+______+_______,______,_+__+___+______,__+___+_______,_+____+______+_______,__+____+_____+______+_______,__+____+_____+______+_______,__+_______,_+___+_____+______+_______,__+____+_____+______+_______,__+____+_____+______+_______,_+__+___+______,__+____,______,______,______,______,_+___+______+_______,___+____+______+_______,_+____+______+_______,__+___+______+_______,______,_+____+______+_______,_+___+______,_+__+_____+______,______,_+___+____+_____+______,_+___+____+_____+______,______,_____+______,__+____+_____+______,__+____,______,______,______,______,______,______,______,______,_____+______+_______,__+_____+______+_______,_+____+______+_______,__+___+____+______+_______,___+_____+______+_______,______,_+__+___+______,__+___+_______,_+____+______+_______,__+____+_____+______+_______,__+____+_____+______+_______,_+__+___+______,__+____,______,______,______,______,_+___+______+_______,___+____+______+_______,_+____+______+_______,__+___+______+_______,______,_+____+______+_______,_+___+______,_+___+_____+______,______,_+___+____+_____+______,_+___+____+_____+______,______,_____+______,__+____+_____+______,__+____,______,______,______,______,______,______,______,______,_____+______+_______,__+_____+______+_______,_+____+______+_______,__+___+____+______+_______,___+_____+______+_______,______,_+__+___+______,__+_______,_+___+_____+______+_______,__+____+_____+______+_______,__+____+_____+______+_______,_+__+___+______,__+____,______,______,______,______,_+___+______+_______,___+____+______+_______,_+__+_____+______+_______,_+___+______+_______,__+____+_____+______,__+____,______,______,______,______,______,______,______,______,_____+______+_______,__+_____+______+_______,_+____+______+_______,__+___+____+______+_______,___+_____+______+_______,______,_+____+______+_______)