Using Python 2.7 I had this code:
#Create a random 56 bit (7 byte) string
random_bytes = os.urandom(7)
random_bytes = int.from_bytes(random_bytes, byteorder="big")
Which gives the error:
AttributeError: type object 'int' has no attribute 'from_bytes'
After reading online it looks like from_bytes
is Python 3. So I tried the following:
random_bytes = os.urandom(7)
#random_bytes = int.from_bytes(random_bytes, byteorder="big")
random_bytes = struct.unpack('>16B', random_bytes)
But this gives the following error:
struct.error: unpack requires a string argument of length 16
Should the >16B
be >7B
? Even with that it seems to return a tuple.
The goal is to use random_bytes
like this:
int(str(((time_bytes << 56) | random_bytes)) + code)