In our Python codebase, some random bytes were generated that we wanted to be cryptographically secure. Previously, the code was:
capability = "".join(secrets.choice(string.digits) for i in range(33))
I've changed it to:
capability = secrets.token_bytes(16)
By my estimation, the first version chose 33 times between 10 digits and so had 33*log2(10)=110bits of entropy, while the second has 128bits of entropy. Is this calculation correct?
bytes
orbytearray
for Python 3 $\endgroup$