Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bytes and integers and concatenation and python

Tags:

python

md5

byte

I have 2 32bit unsigned integers..

777007543 and 114997259

and the string of bytes..

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

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

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

If anyone could run that through in python code it would be much appreciated

like image 607
user558383 Avatar asked Jan 21 '23 19:01

user558383


1 Answers

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']
like image 144
Bill Lynch Avatar answered Jan 30 '23 07:01

Bill Lynch