I have buf="\x00\xFF\xFF\xFF\xFF\x00"
how can i get the "\xFF\xFF\xFF\xFF"
randomized?
In Python, a byte string is just that: a sequence of bytes. It isn't human-readable. Under the hood, everything must be converted to a byte string before it can be stored in a computer. On the other hand, a character string, often just called a "string", is a sequence of characters. It is human-readable.
2 bytes per char (UCS-2 encoding)
random_bytes(int $length ): string. Generates an arbitrary length string of cryptographic random bytes that are suitable for cryptographic use, such as when generating salts, keys or initialization vectors.
>>> import os >>> "\x00"+os.urandom(4)+"\x00" '\x00!\xc0zK\x00'
An alternative way to obtaining a secure random sequence of bytes could be to use the standard library secrets
module, available since Python 3.6.
Example, based on the given question:
import secrets b"\x00" + secrets.token_bytes(4) + b"\x00"
More information can be found at: https://docs.python.org/3/library/secrets.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With