您的位置:首页 > 编程语言 > Python开发

原创 计算检验和:将消息头+会话头+事务头+操作消息按32位异或(Python版)

2007-10-30 09:57 453 查看
版权所有,转载请注明出处与作者

# -*- coding: iso-8859-1 -*-
#!/usr/bin/python
# Author:JiangXiaoQiang

# E-mail:athlong@hotmail.com
# Webpage:www.awrhyme.cn
import binascii
q=[]
def crc64(msg):
s0=00
s2=00
s3=00
s1=00
i=0
j=0
restr=''
l=len(msg)
while i<l:
s0^=ord(msg[i])
s1^=ord(msg[i+1])
s2^=ord(msg[i+2])
s3^=ord(msg[i+3])
i+=4
q.append(~s0)
q.append(~s1)
q.append(~s2)
q.append(~s3)
while j<4:
restr+=contr(q[j])
j+=1
return restr.replace('0x','').upper()
def contr(q):
high = (q& 0xf0) >> 4
low = (q& 0xf)
print 'high',high,'low',low
return(str(hex(high))+str(hex(low)))
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: