who said python can't be obsfucated!?

C

cokofreedom

def s(c):return[]if c==[]else s([_ for _ in c[1:]if _<c[0]])+[c[0]]
+s([_ for _ in c[1:]if _>=c[0]])

Anyone else got some wonders...?
 
B

bearophileHUGS

cokofree...:
def s(c):return[]if c==[]else s([_ for _ in c[1:]if _<c[0]])+[c[0]]+s([_ for _ in c[1:]if _>=c[0]])

That QuickSort can be written as a lambda too:

s=lambda l:[]if l==[]else s([x for x in l[1:]if x<l[0]])+[l[0]]+s([x
for x in l[1:]if x>=l[0]])

Bye,
bearophile
 
B

Bruno Desthuilliers

(e-mail address removed) a écrit :
def s(c):return[]if c==[]else s([_ for _ in c[1:]if _<c[0]])+[c[0]]
+s([_ for _ in c[1:]if _>=c[0]])

Anyone else got some wonders...?

Nothing as bad, but:

sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p
in m.split('@')])
 
M

Marco Mariani

Bruno said:
sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p
in m.split('@')])


Pff... you call that a quicksort?


From http://www.p-nand-q.com/python/obfuscated_python.html


import sys

funcs = range(10)

def A(_,o):
_[3]=_[5]()

def B(_,o):
o[_[2]]=_[9]()

def C(_,o):
_[3]=_[7]()

def D(_,o):
o[_[1]]=_[14]()

def E(_,o):
_[1]=_[4]()

def F(_,o):
_[2]=_[6]()

def G(_,o,O):
if _[O[0]]():return O[-1](_,o) or 1

def H(o, start, stop):
_=[o[stop],[lambda x,y:x+y,lambda x,y:x-y,lambda x,
y:y|1,0,0][1](start,funcs[4](range(funcs[3](),
len(o[:])))),stop,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

for i in range(4,19):
_=lambda _=_,o=o,s="reduce([lambda x,y:x+y,lambda "\
"x,y:x-y,lambda x,y:y|1,0,0][0],[_[1],funcs[4]("\
"range(eval(\"funcs[3]()\"),_[10]()))])$funcs[4"\
"](range(eval(\"funcs[3]()\"),_[10]()))$[lambda"\
" x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,0,0][1]"\
"(_[2],funcs[4](range(funcs[3](),_[10]())))$fun"\
"cs[4](range(funcs[3](),_[10]()))$range(_[10]()"\
"*_[10]())$o[:][_[1]]$len(o[:])$not _[3]$_[1]=="\
"_[2]$o[:][_[1]]>_[0]$o[:][_[2]]$o[_[2]]<_[0]$_"\
"[2]==_[1]$_[11]() and not E(_,0) and not G(_,o"\
",[12,A]) and not G(_,o,[13,B])$_[11]() and not"\
" F(_,_) and not G(_,o,[16,C]) and not G(_,o,[1"\
"5,D])".split('$')[:][i-4]:eval("eval('eval(s)')")

while _[11]():
while _[17](): pass
while _[18](): pass
o[_[2]] = _[0]
return _[2]

def quicksort(list,start,stop):
exec('funcs[3] = lambda:reduce([lambda x,y:x+y,lambda x,y'\
':x-y,lambda x,y:y|1,0,0][1],[[lambda x,y:x+y,lambda'\
' x,y:x-y,lambda x,y:y|1,0,0][2](200,200)]*2)\nfuncs'\
'[4] = lambda x:reduce(lambda x,y:y%2,range(eval("re'\
'duce([lambda x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,'\
'0,0][2],[len(o[:]),len(o[:])])"),eval("reduce([lamb'\
'da x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,0,0][2],[l'\
'en(o[:]),len(o[:])])")+((len(o)and 3)or 3)))\nif st'\
'art < stop:\n\tsplit = H(list, start, stop)\n\tquic'\
'ksort(list, start, [lambda x,y:x+y,lambda x,y:x-y,l'\
'ambda x,y: y|1,0,0][1](split,funcs[4](funcs[3]())))'\
'\n\tquicksort(list, reduce([lambda x,y:x+y,lambda x'\
',y:x-y,lambda x,y:y|1,0,0][0],[split,funcs[4](funcs'\
'[3]())]), stop)\n')

# test code: 2000 elements to sort
list = []
import whrandom,time
for i in range(2000):
list.append(whrandom.randint(1,100))
start = time.clock()
quicksort(list,0,len(list)-1)
print "Sorting took %.2f" % (time.clock() - start)

# just a test loop to see if everything *is* sorted
element = -1
for i in list:
if i >= element:
element = i
else:
print "FUNK DAT: %20s" % str(i)
break
 
M

Marco Mariani

Bruno said:
sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p
in m.split('@')])


Pff... you call that a quicksort?


From http://www.p-nand-q.com/python/obfuscated_python.html


import sys

funcs = range(10)

def A(_,o):
_[3]=_[5]()

def B(_,o):
o[_[2]]=_[9]()

def C(_,o):
_[3]=_[7]()

def D(_,o):
o[_[1]]=_[14]()

def E(_,o):
_[1]=_[4]()

def F(_,o):
_[2]=_[6]()

def G(_,o,O):
if _[O[0]]():return O[-1](_,o) or 1

def H(o, start, stop):
_=[o[stop],[lambda x,y:x+y,lambda x,y:x-y,lambda x,
y:y|1,0,0][1](start,funcs[4](range(funcs[3](),
len(o[:])))),stop,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

for i in range(4,19):
_=lambda _=_,o=o,s="reduce([lambda x,y:x+y,lambda "\
"x,y:x-y,lambda x,y:y|1,0,0][0],[_[1],funcs[4]("\
"range(eval(\"funcs[3]()\"),_[10]()))])$funcs[4"\
"](range(eval(\"funcs[3]()\"),_[10]()))$[lambda"\
" x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,0,0][1]"\
"(_[2],funcs[4](range(funcs[3](),_[10]())))$fun"\
"cs[4](range(funcs[3](),_[10]()))$range(_[10]()"\
"*_[10]())$o[:][_[1]]$len(o[:])$not _[3]$_[1]=="\
"_[2]$o[:][_[1]]>_[0]$o[:][_[2]]$o[_[2]]<_[0]$_"\
"[2]==_[1]$_[11]() and not E(_,0) and not G(_,o"\
",[12,A]) and not G(_,o,[13,B])$_[11]() and not"\
" F(_,_) and not G(_,o,[16,C]) and not G(_,o,[1"\
"5,D])".split('$')[:][i-4]:eval("eval('eval(s)')")

while _[11]():
while _[17](): pass
while _[18](): pass
o[_[2]] = _[0]
return _[2]

def quicksort(list,start,stop):
exec('funcs[3] = lambda:reduce([lambda x,y:x+y,lambda x,y'\
':x-y,lambda x,y:y|1,0,0][1],[[lambda x,y:x+y,lambda'\
' x,y:x-y,lambda x,y:y|1,0,0][2](200,200)]*2)\nfuncs'\
'[4] = lambda x:reduce(lambda x,y:y%2,range(eval("re'\
'duce([lambda x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,'\
'0,0][2],[len(o[:]),len(o[:])])"),eval("reduce([lamb'\
'da x,y:x+y,lambda x,y:x-y,lambda x,y:y|1,0,0][2],[l'\
'en(o[:]),len(o[:])])")+((len(o)and 3)or 3)))\nif st'\
'art < stop:\n\tsplit = H(list, start, stop)\n\tquic'\
'ksort(list, start, [lambda x,y:x+y,lambda x,y:x-y,l'\
'ambda x,y: y|1,0,0][1](split,funcs[4](funcs[3]())))'\
'\n\tquicksort(list, reduce([lambda x,y:x+y,lambda x'\
',y:x-y,lambda x,y:y|1,0,0][0],[split,funcs[4](funcs'\
'[3]())]), stop)\n')

# test code: 2000 elements to sort
list = []
import whrandom,time
for i in range(2000):
list.append(whrandom.randint(1,100))
start = time.clock()
quicksort(list,0,len(list)-1)
print "Sorting took %.2f" % (time.clock() - start)

# just a test loop to see if everything *is* sorted
element = -1
for i in list:
if i >= element:
element = i
else:
print "FUNK DAT: %20s" % str(i)
break
 
B

Bruno Desthuilliers

Marco Mariani a écrit :
Bruno said:
sig=lambda m:'@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p
in m.split('@')])


Pff... you call that a quicksort?

Nope, only somewhat obfuscated Python. And it seems it's at least
obfuscated enough for you to believe it could be a quicksort
implementation !-)
 
M

Marco Mariani

Bruno said:
Nope, only somewhat obfuscated Python. And it seems it's at least
obfuscated enough for you to believe it could be a quicksort
implementation !-)

You're right, but I'm past the quine age and don't bother parsing
obfuscated code (*) anymore.




(*) outside my day job, that is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top