Heim  >  Artikel  >  Backend-Entwicklung  >  python - 此段PY代码可以帮忙转换成PHP?

python - 此段PY代码可以帮忙转换成PHP?

WBOY
WBOYOriginal
2016-10-10 11:56:021530Durchsuche

作为PY菜鸟的我看这PY代码等于是天书一样,大家可以帮忙转换成PHP吗?

<code>def str2hex(s):
        r=""
        for i in s[:8]:
            t=hex(ord(i))[2:]
            if len(t)==1:
                t="0"+t
            r+=t
        for i in range(16):
            r+=hex(int(15*random()))[2:]
        return r

    def getkey(s):
        #returns 1896220160
        l2=[i for i in s]
        l4=0
        l3=0
        while l4<len l5="l2[l4]" l6="ord(l5)" l7="l6<<((l4%4)*8)" l3="l3^l7" l4 return pass></len></code>

回复内容:

作为PY菜鸟的我看这PY代码等于是天书一样,大家可以帮忙转换成PHP吗?

<code>def str2hex(s):
        r=""
        for i in s[:8]:
            t=hex(ord(i))[2:]
            if len(t)==1:
                t="0"+t
            r+=t
        for i in range(16):
            r+=hex(int(15*random()))[2:]
        return r

    def getkey(s):
        #returns 1896220160
        l2=[i for i in s]
        l4=0
        l3=0
        while l4<len l5="l2[l4]" l6="ord(l5)" l7="l6<<((l4%4)*8)" l3="l3^l7" l4 return pass></len></code>

代码写得好不专业。。。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn