10 Replies - 3633 Views - Last Post: 05 May 2011 - 06:39 AM Rate Topic: -----

#1 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Obfuscation Challenge

Post icon  Posted 01 May 2011 - 04:12 PM

*
POPULAR

I am stealing one of AdamSpeight2008's challenges! This is a simple one, make a hello World program that is as cryptic and hard to read as possible!!

I'll go first :)

from random import seed as staplerInJello
from random import shuffle as dwightSchrute
staplerInJello(42)
ryan = ''
desireToDestroyJim = ['d', 'l', 'l', 'H', 'W', 'o', 'l', '!', 'e', 'r', 'o', ' ']
dwightSchrute(desireToDestroyJim)

print(ryan.join(desireToDestroyJim))



You may use any version of Python you wish. Let's see who can create the craziest Hello World!

This post has been edited by atraub: 02 May 2011 - 06:54 AM


Is This A Good Question/Topic? 5
  • +

Replies To: Obfuscation Challenge

#2 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Obfuscation Challenge

Posted 03 May 2011 - 06:44 AM

Wow, no one wants to take up the challenge?
Was This Post Helpful? 0
  • +
  • -

#3 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Obfuscation Challenge

Posted 03 May 2011 - 06:52 PM

I had to get reasonably stoned to take up that "challenge":
obf = ['&', '6', 'N', '\xf6', '\xea', '\x04', '\xf6', '6', '6', '\xa6', '\x12']
obf = [bin(ord(c))[2:].rjust(8, "0") for c in obf]
tr = lambda seq: list(reversed(zip(*seq)))
print "".join([chr(int("".join(list(r)), 2)) for r in tr(tr(obf))])



A little explanation:
the tr = ... line takes a 2d array and rotates it counter-clockwise by 90 degrees (shamelessly stolen from functional programming). I hope that doesn't help too much to understand the code ^-^

Edit: No one said you cannot write obfuscated python. Last Pycon there was a talk that showed BrainF* implemented in Python using only decorators :online2long:

This post has been edited by Nallo: 03 May 2011 - 07:02 PM

Was This Post Helpful? 2
  • +
  • -

#4 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Obfuscation Challenge

Posted 04 May 2011 - 06:42 AM

That's awesome!
Was This Post Helpful? 0
  • +
  • -

#5 Shane Hudson  Icon User is offline

  • D.I.C Technophile
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,286
  • Joined: 06-December 09

Re: Obfuscation Challenge

Posted 04 May 2011 - 08:29 AM

Hmm, I focus very hard on writing readable code, especially in languages I am not great with. But I shall give it a go!

EDIT:

Haha my attempt is terrible but ah well! The reason why all letters/numbers are doubled is to prevent mismatches as it replaces what has already been replaced. Certainly nothing impressive to see as I come from a C-based language background and python is rather different so am still not up to scratch with it!

a="tt33iiii99cc229944iiww";b=a;b=b.replace("tt","h");b=b.replace("33","e");b=b.replace("ii","l");b=b.replace("99","o");b=b.replace("cc"," ");b=b.replace("22","w");b=b.replace("44","r");b=b.replace("ww","d")


This post has been edited by Shane Hudson: 04 May 2011 - 10:07 AM

Was This Post Helpful? 1
  • +
  • -

#6 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Obfuscation Challenge

Posted 04 May 2011 - 01:02 PM

One more version:

"""Hello World"""

print (lambda z:(lambda x, _ = 'b~qfm iJ>se]3HY!y4O}@`vgIBl&a\\nRd)Tc<,APr?|GK#;05:N6Z89("[$wkEDWz.V+-x2*=uSjX\'h^7QtFMC%p/oU_1{L_': __builtins__.__dict__[x[:(z<<2)-1].translate(("-"*(z<<4)+_)*z)]()[x[9-z:].translate(("_"*(z<<4)+_)*z)]))(2)('7:y <:)/>{{@yC{{')



If you want to run it don't remove the docstring of the programm.
Was This Post Helpful? 2
  • +
  • -

#7 atraub  Icon User is offline

  • Pythoneer
  • member icon

Reputation: 759
  • View blog
  • Posts: 2,010
  • Joined: 23-December 08

Re: Obfuscation Challenge

Posted 04 May 2011 - 01:27 PM

I salute you sir.
Was This Post Helpful? 0
  • +
  • -

#8 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Obfuscation Challenge

Posted 04 May 2011 - 02:15 PM

Two more.
First one is quite readable though, if you understand decorators:
"""Hello World"""

def hw_decorator(func):
    def func_wrapper(*args):
        result = func(*args)
        return result + 1
    return globals()["__doc__"]

@hw_decorator
def useless(x, y, z):
    return x + y + z

print useless



Second one consists of two files:
star_import_buster.py
#this module will teach you why * imports are frowned upon
#lots of lines with many function/class definitions follow
#and somewhere deeply hidden inside is this little line:
True, False = False, True


and the main programm:
from star_import_buster import *

if (1 == 1) is True:
    print "I wont greet the world"
else:
    print "Hello World"


Was This Post Helpful? 1
  • +
  • -

#9 Nallo  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 163
  • View blog
  • Posts: 255
  • Joined: 19-July 09

Re: Obfuscation Challenge

Posted 04 May 2011 - 04:07 PM

One more. Time to take that butchers knive and mess a little bit with python internals. Unfortunately I don't have enough understanding of pythons internals to make this really unreadable.
#probably only works in cpython 2.6
from types import CodeType

hw = "Hello World"

def f(x):
    return x

co = CodeType(1, 1, 1, 67, 't\x01\x00S', (None,), ('bs', 'hw', 'cs'), ('x',),
 f.func_code.co_filename, 'f', 6, '\x00\x01')
f.func_code = co
print f("blah")


This post has been edited by Nallo: 04 May 2011 - 04:14 PM

Was This Post Helpful? 0
  • +
  • -

#10 Shane Hudson  Icon User is offline

  • D.I.C Technophile
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,286
  • Joined: 06-December 09

Re: Obfuscation Challenge

Posted 05 May 2011 - 05:20 AM

Slightly off topic... Nallo for Python expert! Nallo for Python expert! Nallo for Python expert! Nallo for Python expert!
Was This Post Helpful? 0
  • +
  • -

#11 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: Obfuscation Challenge

Posted 05 May 2011 - 06:39 AM

def y(n):
	while n>0:
		yield((n & ((((((((((1<<1)+1)<<1)+1)<<1)+1)<<1)+1)<<1)+1)))
		n = n >> (((1<<1)+1)<<1)

print ''.join([ chr(c+32) for c in y(42312091937656719720L) ])



For those interested in the silly encoded n:
Spoiler

Was This Post Helpful? 3
  • +
  • -

Page 1 of 1