@
wsy2220 python 得不到想要的结果
import hashlib
import hmac
base = [str(x) for x in range(10)] + [ chr(x) for x in range(ord('A'),ord('A')+6)]
#10->2
def dec2bin(string_num):
num = int(string_num)
mid = []
while True:
if num == 0: break
num,rem = divmod(num, 2)
mid.append(base[rem])
return ''.join([str(x) for x in mid[::-1]])
#16->10
def hex2dec(string_num):
return str(int(string_num.upper(), 16))
#16->2
def hex2bin(string_num):
return dec2bin(hex2dec(string_num.upper()))
key = "123456"
msg = hex2bin('0015025c01000000001a1ecf006a0000')
print msg
m = hmac.new(key, msg, hashlib.sha1)
signature = m.hexdigest()
print signature
-------------------------------
101010000001001011100000000010000000000000000000000000000000000011010000111101100111100000000011010100000000000000000
29c6662533383f42db96fa6a7f82f265aa1b84e8