问题描述
我有2个32位无符号整数.
I have 2 32bit unsigned integers..
777007543和114997259
777007543and114997259
和字节字符串..
0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58
0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58
我如何获取python以将这3个对象串联起来...
How do I get python to give me the concatenation of these 3 such that I have...
0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58
0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58
然后我将其通过md5哈希运行并获取...
I would then run that through an md5 hash and get...
0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A 0x55 0x5E 0x77 0x65 0x75
0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A 0x55 0x5E 0x77 0x65 0x75
如果任何人都可以用python代码运行它,将不胜感激
If anyone could run that through in python code it would be much appreciated
推荐答案
import struct
import hashlib
x = struct.pack('>II8B', 777007543, 114997259, 0x47, 0x30, 0x22, 0x2D, 0x5A, 0x3F, 0x47, 0x58)
hash = hashlib.md5(x).digest()
print [hex(ord(d)) for d in x]
(output) ['0x2e', '0x50', '0x31', '0xb7', '0x6', '0xda', '0xb8', '0xb', '0x47', '0x30', '0x22', '0x2d', '0x5a', '0x3f', '0x47', '0x58']
print [hex(ord(d)) for d in hash]
(output) ['0x30', '0x73', '0x74', '0x33', '0x52', '0x6c', '0x26', '0x71', '0x2d', '0x32', '0x5a', '0x55', '0x5e', '0x77', '0x65', '0x75']
这篇关于字节和整数以及串联和python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!