Key entropy for different character sets and charactersKey entropy is the measurement of the equivalent number of bits that would represent the number of options that we have for a password or for an encryption key. If we have 1,024 possible passwords, this represents 10 bits of entry. To compute entropy we use \(E=log_2(x)\) and where \(x\) is the number of options that we have. As most calculators do not have a \(log_2()\) function, we can use: \(E=log_{10}(x)/log_{10}(2)\). |
Theory
Key entropy is the measurement of the equivalent number of bits that would represent the number of options that we have for a password or for an encryption key. If we have 1,024 possible passwords, this represents 10 bits of entropy. To compute entropy we use:
\(E=\log_2(x)\)
and where \(x\) is the number of options that we have. As most calculators do not have a \(log_2()\) function, we can use:
\(E=\frac{\log_{10}(x)}{\log_{10}(2)}\)
In this calculation. If we have \(c\) for the count of the characters and \(n\) is the number of characters, we get:
\(E=\frac{\log_{10}(c^n)}{\log_{10}(2)} \)
and from the rules of logs we get:
\(E=\frac{n \log_{10}(c)}{\log_{10}(2)} \)
In C#, the code for this is:
n=5; c=26; val = Math.Round(n * (Math.Log10(c) / Math.Log10(2)), 2);
and in Python:
import math n=5 c=26 no_pass=c**5 E=n*math.log(c)/math.log(2) print(f"Character range: {c}") print (f"Number of characters in password: {n}") print ("Number of passwords: ",no_pass) print (f"Key entropy: {round(E,2)}")
and a sample run is:
Character range: 26 Number of characters in password: 5 Number of passwords: 11881376 Key entropy: 23.5