我有 2 个 32 位无符号整数..

777007543

114997259

和字节串..

0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58

我如何让 python 给我这 3 个的连接,这样我就...

0x2E 0x50 0x31 0xB7 0x06 0xDA 0xB8 0x0B 0x47 0x30 0x22 0x2D 0x5A 0x3F 0x47 0x58

然后我会通过 md5 哈希运行它并得到......

0x30 0x73 0x74 0x33 0x52 0x6C 0x26 0x71 0x2D 0x32 0x5A 0x55 0x5E 0x77 0x65 0x75

如果有人可以在 python 代码中运行它,将不胜感激

最佳答案

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 - 字节和整数以及连接和 python,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4595161/

10-11 23:16