Python: A recipe for cryptic code?巨蟒:食谱潜代码?
I have heard that Python is a great programming language which is so much superior to everything around etc.我听说巨蟒是一个伟大的编程语言,这是这么多优于一切靠近等。
The following code in python is touted as the world’s smallest p2p client & server.以下代码在巨蟒是吹捧为世界上最小的P2P的客户端与伺服器。
# tinyp2p.py 1.0 (documentation at http://freedom-to-tinker.com/tinyp2p.html) # tinyp2p.py 1.0 (文件http://freedom-to-tinker.com/tinyp2p.html )
import sys, os, SimpleXMLRPCServer, xmlrpclib, re, hmac # (C) 2004, EW Felten进口系统,操作系统, simplexmlrpcserver , xmlrpclib ,转口, hmac # (三) 2004年,电子战felten
ar,pw,res = (sys.argv,lambda u:hmac.new(sys.argv[1],u).hexdigest(),re.search)氩,晚上八时,第= ( sys.argv ,波长u : hmac.new ( sys.argv [ 1 ] , u )的。 hexdigest ( ) , re.search )
pxy,xs = (xmlrpclib.ServerProxy,SimpleXMLRPCServer.SimpleXMLRPCServer) pxy , XS的= ( xmlrpclib.serverproxy , simplexmlrpcserver.simplexmlrpcserver )
def ls(p=”"):return filter(lambda n:(p==”")or res(p,n),os.listdir(os.getcwd()))高清康乐事务性( P =""):返回过滤器(波长n :性( P =="")或第性( P , N )基金, os.listdir ( os.getcwd ( ) ) )
if ar[2]!=”client”: # license: http://creativecommons.org/licenses/by-nc-sa/2.0如果氩[ 2 ] ! = “客户端” : #许可: http://creativecommons.org/licenses/by-nc-sa/2.0
myU,prs,srv = (”http://”+ar[3]+”:”+ar[4], ar[5:],lambda x:x.serve_forever()) myu ,公共无线电通讯服务,的SRV = (以“ http:// ” +氩[ 3 ]+":"+氩[ 4 ] ,氩[ 5 : ] ,波长x : x.serve_forever ( ) )
def pr(x=[]): return ([(y in prs) or prs.append(y) for y in x] or 1) and prs高清公关(十=[]):回报( [ ( Y在公共无线电通讯服务)或prs.append (元Y )为Y在X ]的或1 )及PRS
def c(n): return ((lambda f: (f.read(), f.close()))(file(n)))[0]高清( n )的标准: Return ( (的LAMBDA传真: ( f.read ( ) , f.close ()))(档案( n )段) ) [ 0 ]
f=lambda p,n,a:(p==pw(myU))and(((n==0)and pr(a))or((n==1)and [ls(a)])or c(a))女=的LAMBDA磷,氮, 1 :性( P ==四十五分( myu ) )及( ( ( == 0 )和PR (一) )或( ( == 1 )和[ LS (上一) ] )或(一) )
def aug(u): return ((u==myU) and pr()) or pr(pxy(u).f(pw(u),0,pr([myU])))高清八月( u )的标准: Return ( ( u == myu )和PR ( ) )或公关( pxy ( u )的。 F (下四十五分( u )的, 0 , Pr (上[ myu ] ) ) )
pr() and [aug(s) for s in aug(pr()[0])] Pr (上)和[月8日电( )为S在八月( Pr (上) [ 0 ] ) ]
(lambda sv:sv.register_function(f,”f”) or srv(sv))(xs((ar[3],int(ar[4])))) (波长sv : sv.register_function (男, “ F ”类)或的SRV ( sv ) ) ( XS的( (氩[ 3 ] ,诠释(氩[ 4 ]))))
for url in pxy(ar[3]).f(pw(ar[3]),0,[]):为网址在pxy (氩[ 3 ] ) 。 F (下四十五分(机铁[ 3 ] ) , 0 ,[]):
for fn in filter(lambda n:not n in ls(), (pxy(url).f(pw(url),1,ar[4]))[0]):为Fn的过滤器(波长n :不N的LS (上) , ( pxy器( URL ) 。 F (下四十五分器( URL ) , 1 ,氩[ 4 ] ) ) [ 0 ] ) :
(lambda fi:fi.write(pxy(url).f(pw(url),2,fn)) or fi.close())(file(fn,”wc”)) ( Fi的的LAMBDA : fi.write ( pxy器( URL ) 。 F (下四十五分器( URL ) , 2 , FN )的)或fi.close ( ) ) (档案( FN的, “厕所” ) )
Source:资料来源: TinyP2P tinyp2p
I started my programming career with assembly language (writing tiny .com programs and playing with cuties like masm and tasm), then moved to C, even mess with java byte codes for fun.我一开始我的职业生涯规划与汇编语言(写作微小。 com的程序和公平与cuties一样, masm和tasm ) ,然后转移到C ,甚至一塌糊涂,与Java字节码的乐趣。
But this wonderful gem of a program (displayed above) beat the crap out of me.但这个美好的创业板市场的一个程序(显示以上)击败crap出了我。
Python, going by this example, looks to me a sure-fire recipe for creating obfuscated code.巨蟒,前往由这个例子,看来我肯定会火的处方,创造模糊代码。 I would rather read 80×86 instructions, thank you very much!我宁愿读80 × 86的指示,非常感谢你!
PS.保安局常任秘书长。 Java programmers, you can relax. Java程序员,您可以放宽。 Python programmers (oops hackers as per naive bayesian dude) writing such code will never be able to maintain it. Python的程序员(哎呀黑客作为每朴素贝叶斯dude )以书面形式,如代码将永远无法维持。 So you will definitely be called in to replace such “hackers” and rewrite the whole thing in Java (use the word refactoring to get better traction with management).所以你一定会被称为在以取代这种“黑客”和重写整个事情在Java (使用Word的重构,以得到更好的牵引与管理) 。
Filed under提起下 Humor幽默 , , Java Software Java软件 , , Technology技术 , , Web网页 , , Web Services Web服务 | |
| |
RSS 2.0 2.0 | |
Email this Article电子邮件此文章
You may also like to read您也可以想读 |




April 13th, 2005 at 3:55 am 2005年4月13日在上午03时55分
I’ma java programmer (and an occasioanl python/jython one).我的Java程序员( 1 occasioanl巨蟒/ jython 1 ) 。 But this is not really fair.不过,这并非真正公平的。 One can write obfuscated code in any language.一可以写模糊代码,在任何一种语言。 This code is like when you write multiple statments in one line in any C style language (like in java).此代码是一样,当您写信多个statments在同一行,在任何c风格的语言(如Java语言) 。 Or you can nest a lot of method calls, which you normally don’t do if you wan’t maintanable code.或者您也可以巢了很多方法调用,您通常不这样做如果您wan't maintanable代码。
This code is meant to be compact and not readible or maintainable.此代码是要紧凑,而不是readible或维护。 There are no blocks (no indentations) only one liner methods and lambda (inline defined) functions.有没有座(无indentations )只有一个方法和班轮运输的LAMBDA (内嵌定义)的功能。 Python does look good when you program it in the right, standard style.巨蟒看起来的确好当您计划,它是在正确的,标准的作风。 And there is such a thing, just as with java (though there are some annoying inconsistencies, like some people and the stdlib uses camel case here and underscores there, etc).有这样的事,正如与Java (虽然也有一些恼人的不一致,像有些人及stdlib使用骆驼在这里的情况,并强调有等) 。
April 13th, 2005 at 5:06 am 2005年4月13日在上午05时06分
Be sure to catch the readable rebuke一定要赶上可读的指责
: :
http://www.mechanicalcat.net/richard/log/Python/Ugly_Python http://www.mechanicalcat.net/richard/log/python/ugly_python
…wonder if that runs in Jython? …难怪,如果运行在jython ?
April 13th, 2005 at 5:14 am 2005年4月13日在上午05时14分
@Laszlo Marai @拉兹洛marai
> But this is not really fair. >但是,这并不是真正的公平。
Life isn’t fair either生活是不公平的要么
BTW: You mentioned that the code is meant to be compact and not readable or maintable.的BTW :你所提到的该守则是要紧凑,无法读取或maintable 。 Then why did he code it in Python?那么,为什么他的代码,它在巨蟒? Why not in assembly language?为什么没有在大会语言? It would have been much faster and more compact.它将已更快,更紧凑。
Any code written in high level language should be readable and maintable.任何编写的代码在高层次的语言应该是可读和maintable 。
I seriously doubt you can match this level of obfuscation in Java. i严重怀疑,您可以匹配这一级别的困惑在Java 。 Heck I can even read the decompiled obfuscated(using standard obfuscators; not by the programmer) java code properly.赫克我什至可以读解编模糊(使用标准obfuscators ;不是由程序员) Java代码。
PS: Be sure to check the categories this post is under. PS :如果请务必检查该类别的这个职位是根据。
April 13th, 2005 at 5:32 am 2005年4月13日在上午05时32分
From自 http://www.gamedev.net/hosted/javaextreme/obfpoll.htm : :
import java.awt.*;import java.util.*;public class C extends Frame{Date D=new Date();void T(Date d){D=d;repaint();}double P=Math.PI,A=P/2,a,c,U=.05;int W,H,m,R;double E(int a,int u){return(3*P/2+2*P*a/u)%(2*P);}void N(Graphics g,double q,double s){g.fillPolygon(new int[]{H(s,q),H(U,q+A),H(U,q+3*A)},new int[]{J(s,q),J(U,q+A),J(U,q+3*A)},3);}public void paint(Graphics g){Color C=SystemColor.control;g.setColor(C);g.fillRect(0,0,W=size().width,H=size().height);W-=52;H-=52;R=Math.min(W/2,H/2);g.translate(W/2+25,H/2+36);g.setColor(C.darker());for(m=0;m javac C.java进口java.awt .* ;进口java.util .* ;公共C级扩展帧(日期=新的日期( ) ;无效吨(日期四) ( =深; repaint ( ) ; )双P值math.pi , =普/ 2 , , C类,美国=. 05 ;诠释瓦特, H型,米,右;双E (下诠释,诠释u )的(返回( 3 *普/ 2 2 * * / u ) % ( 2 *普) ; )无效N (下图形克,双重的Q双) ( g.fillpolygon (新诠释[ ] ( h ( , q )的, H (下铀, q + 1 ) , H (上u , q 3 * ) ) ,新的诠释[ ] ( j ( , q )的, J (下铀, q + 1 ) , J (下铀, q 3 * ) ) , 3 ) ; )公共无效涂料(图形克) (颜色c = systemcolor.control ; g.setcolor ( c )段; g.fillrect ( 0,0 ,大小为W = ( ) 。宽度,大小为H = ( ) 。高度) ;瓦特- = 52 ;的H - = 52 ; r = math.min (瓦特/ 2 ,的H / 2 ) ; g.translate (瓦特/ 2 25 ,的H /二36 ) ; g.setcolor ( c.darker ( ) ) ; (米= 0 ;米javac c.java
C> java C c > Java的c
Author & Submitter: David M. Hewitt/1999″作者&提交者:大卫米休伊特/ 1999年“
April 13th, 2005 at 6:37 am 2005年4月13日在上午06时37分
not the shortest p2p app, there is at least a shorter one in ruby and an even shorter one in perl.不能在最短的P2P的应用程序,至少有一短一在红宝石和更短的一在Perl 。
See看见
http://ruby-talk.org/cgi-bin/scat.rb/ruby/ruby-talk/123945
for the first, I can’t find the latter.为首先,我无法找到了后者。
Btw, doing this things in python is more impressive.的BTW ,这样做的东西,在巨蟒是更深刻的印象。
April 13th, 2005 at 7:08 am 2005年4月13日在上午07时08分
You picked what is probably the single most obsfucated chunk of Python code in existence and are attempting to make a generalization about the entire language based on it.您挑选什么,可能是唯一最obsfucated大块的Python代码存在,并企图作出概括整个语文的基础上。 It’s folly.它的蠢事。
> Why not in assembly language? >为什么没有在大会语言? It would have been much faster and more compact.它将已更快,更紧凑。
It would have taken longer, required many more lines, and would have been limited to running on a specific platform.它会采取更长的时间,需要更多的线,并会一直局限于运行于特定平台。
> Any code written in high level language should be readable and maintable. >任何代码的书面在高层次的语言应该是可读和maintable 。
More folly.更愚蠢的。 Python syntax *encourages* readable and maintainable code, it doesn’t require it. Python的语法*鼓励*可读和可维护的代码,这并不需要它。
October 3rd, 2007 at 7:21 am 2007年10月3日在上午07时21分
I tend to agree with the artical.我倾向于同意的文章。 Have a look at examples in the Python tutorials:有一个例子,看看在的Python教程:
return “;”.join(["%s=%s" % (k, v) for k, v in params.items()])返回“ ; ” 。加入( [ “的% s = % s ”中% (钾,五)对K , V的params.items ( ) ] )
This statement could easily be written using a loop and be much easier to understand.本声明可轻易的书面使用闭环和更容易理解。 It seems to be cool to Python programmers try to write the entire program in one line and the syntax of the language seems to be designed that way.它似乎是冷淡的Python程序员尝试写入整个计划在1线和语法的语言,似乎是设计的方式。
Java uses plain english keywords that makes it less crytic. Java的使用简单易懂的英语关键词,使少crytic 。