by rybosome · 10y ago · 0 comments
I must admit that I don't understand how the number of characters corresponds to bits of entropy. Know of a resource that explains this?
There are 26 letters; mixed-case doubles that for 52 choices; digits add 10 for a total of 62 possible choices for each character. That means that 2 characters have 62^2 possible configurations, 3 62^3 and so forth. If you take the resulting number and calculate the ceiling of its logarithm in base 2, you get the number of bits needed to represent it:
(ceiling (log (expt 62 11) 2)) → 66 -0.5038376 log(num_options)/log(2)
So for a 8 character digits-only value, num_options is 10^8, so log(power(10, 8))/log(2) = 30 bits. This means both 30 bits needed to store the value and 30 bits of security. It also works for octal or hexadecimal: just replace log(2) with log(n), like log(16) for hexadecimal.