bit 計算の高速化。
@@ -9,7 +9,7 @@ | ||
9 | 9 | import re |
10 | 10 | import urllib2 |
11 | 11 | import cPickle |
12 | -from struct import unpack, pack | |
12 | +from struct import unpack, pack, calcsize | |
13 | 13 | from binascii import unhexlify, hexlify |
14 | 14 | import httplib |
15 | 15 | import socket |
@@ -56,16 +56,22 @@ | ||
56 | 56 | regIP = re.compile(r'(\d+)\.(\d+)\.(\d+)\.(\d+)') |
57 | 57 | m = regIP.match(ip) |
58 | 58 | if not m: raise Exception |
59 | - return hexlify(aesobj.encrypt(pack("B", int(m.group(1)))+ | |
60 | - pack("B", int(m.group(2)))+ | |
61 | - pack("B", int(m.group(3)))+ | |
62 | - pack("B", int(m.group(4)))+"\x00"*12)[:4]) | |
59 | + return hexlify(aesobj.encrypt(pack("4B", int(m.group(1)), | |
60 | + int(m.group(2)), int(m.group(3)), | |
61 | + int(m.group(4)))+"\x00"*12)[:4]) | |
63 | 62 | |
64 | 63 | def hash_xor(a,b): |
65 | 64 | res = "" |
66 | - for i in range(0,len(a)): | |
67 | - res += chr(ord(a[i]) ^ ord(b[i])) | |
68 | - return res | |
65 | + if(len(a) != 20 or len(b) != 20): raise Exception() | |
66 | + if calcsize("L") == 8 and calcsize("I") == 4: | |
67 | + resa = unpack("2LI", a) | |
68 | + resb = unpack("2LI", b) | |
69 | + return pack("2LI", resa[0] ^ resb[0], resa[1] ^ resb[1], resa[2] ^ resb[2]) | |
70 | + elif calcsize("Q") == 8 and calcsize("L") == 4: | |
71 | + resa = unpack("2QL", a) | |
72 | + resb = unpack("2QL", b) | |
73 | + return pack("2QL", resa[0] ^ resb[0], resa[1] ^ resb[1], resa[2] ^ resb[2]) | |
74 | + else: raise Exception() | |
69 | 75 | |
70 | 76 | def hash_bittest(x, pos): |
71 | 77 | return (((ord(x[pos/8]) >> (pos%8)) & 0x01 != 0)) |
@@ -25,6 +25,8 @@ | ||
25 | 25 | import o2on_node |
26 | 26 | |
27 | 27 | def my_replace_handler(inst): |
28 | + if inst.end-inst.start == 1: | |
29 | + return ((u"\u0000", inst.start+1)) | |
28 | 30 | return ((u"\u30fb", inst.start+2)) |
29 | 31 | |
30 | 32 | try: |