代码在python2.7下面跑得很正常 但是到了python3.3 下面就不行了
#coding=utf8
import base64
import struct
from random import seed
from random import randint
from hashlib import md5
import codecs
seed(1)
op = 0xffffffff
delta = 0x9e3779b9
value = b'\x00\x80\xe8\xdec\xd5{\xe0\x1b6\x8f\x97\xbf\xc2F\xb4\x0b\xe1\xa5\xc7\x84h33M\xc2\x18\xc7Y\xb2B\\\xa3\xf8\x9dFH^-p\x07\x13\xa3\xd1\xe8\xb5\xe2\xe8\x82\xb9\xe1\xab\x15\xf1I\xcf\xd6\x98\xb7\x02\xe4\x82\xc8\xb2N\x95\xd4\x03b\x1dF@\\\xf5\xaez/\xc0-\xcaOA\x84\x19\x93l\xf0"\x0b\'\x8f\x1f\xf7\xc9\x830\xa1\xc9\x98\x9d\xad\xd8\x07\x0b\xcdS\x9c\x13[\xddxK\x91\xa4J\xb5\x9b`0%\xccd\xd4\x98\xed\xa4xc)\t\x00\x00\x00\x00D\x87\xe9\xe9\x00\x04WUWV'
key = b")7\xf7:!\xb7\xdetp0'\xf5\xd8\xfaK\x82"
def xor(a, b):
a1,a2 = struct.unpack('>LL', a[0:8])
b1,b2 = struct.unpack('>LL', b[0:8])
r = struct.pack('>LL', ( a1 ^ b1) & op, ( a2 ^ b2) & op)
return r
def code(v, k):
n=16
k = struct.unpack('>LLLL', k[0:16])
y, z = struct.unpack('>LL', v[0:8])
s = 0
for i in range(n):
s += delta
y += (op &(z<<4))+ k[0] ^ z+ s ^ (op&(z>>5)) + k[1]
y &= op
z += (op &(y<<4))+ k[2] ^ y+ s ^ (op&(y>>5)) + k[3]
z &= op
r = struct.pack('>LL',y,z)
return r
def encrypt(v, k):
END_CHAR = b'\0'
fills = b''
filln = ((8-(len(v)+2))%8) + 2
for i in range(filln):
fills = fills + chr(randint(0,0xff))
v = (chr((filln - 2)|0xF8)
+ fills
+ v
+ END_CHAR *7)
tr = to = o = END_CHAR * 8
r = b''
for i in range(0, len(v), 8):
g = v[i:i+8]
o = xor(g,tr)
tr = xor(code(o,k),to)
to = o
r += tr
return r
print(
base64.b64encode(encrypt(value,key)).replace('/', '-').replace('+', '*').replace('=', '_')
)
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.