Javascript代码:
function rstr2binl(d) {
for (var a = Array(d.length >> 2), b = 0; b < a.length; b++) {
a[b] = 0;
}
for (b = 0; b < d.length * 8; b += 8){
a[b >> 5] |= (d.charCodeAt(b / 8) & 255) << b % 32;
}
return a
}
Python代码:
def rstr2binl(d):
a = [0] * (len(d) >> 2)
for b in range(0, len(a), 1):
a[b] = 0
for b in range(0, len(d) * 8, 8):
a[b >> 5] |= (ord(d[b / 8]) & 255 << b) % 32
return a
rstr2binl("abc123456")
Python输出:Error list out of range
JS输出:[ 828596833, 892613426, 54 ]
在JS代码中有些步骤是用 undefined |= (d.charCodeAt(b / 8) & 255) << b % 32;
请问在Python中如何实现呢,或者有其他办法达到这个函数的功能吗
炎炎设计
相关分类