In this post, we discusses an example in which you are given a password (every character of it) and yet it is still very hard (or even impossible) to crack. Anyone who understands this example has a solid understanding of the binomial distribution. Here’s the example:
Your friend John tells you that the password to his online bank account has 26 characters. The first character is the first letter in the English alphabet, the second character is the second letter in the English alphabet, the third character is the third letter in the English alphabet and so on.
Now that your friend John has given you the key to his account, does that mean you can log onto his account to find out how much money he has, or to make financial transaction on his behalf or to enrich yourself?
If this example sounds too good to be true, what is the catch?
Even though every character in the 26-character password is known, it is indeed a very strong password. How could this be? You may want to stop here and think about.
Indeed, if every character in John’s password is lower case or if every character is upper case, then his bank account is toast. But John’s password can be made very strong and very hard to crack if the password is case sensitive. The password given by John is not just one password, but is a large collection of passwords. In fact, there are over 67 millions possible passwords (67,108,864 to be exact). The following are two of the most obvious ones.
a b c d e f g h i j k l m n o p q r s t u v w x y z (all lower case)
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z (all upper case)
The following is another possible password. If this is the one John uses, it will be difficult to crack.
a b C d e f G h i j k l M N o p Q R s T U v w X Y z (10 upper case letters)
Here’s another possibility.
A B c D E f G H I J k l M N o P q R S t u v w X y z (14 upper case letters)
Each character in the password has two possibilities – lower case or upper case. Across all 26 characters, there are possibilities. This number is 67,108,864. So 2 raised to 26 is a little over 67 millions. So the password given by John is not just one password, but is a generic one with over 67 million possibilities. There is a one in 67 million chance in correctly guessing the correct password if John chooses the upper case letters randomly. This is much better odds than winning the Powerball lottery, one in 292,201,338, which one in 292 million. But it is still an undeniably strong password.
So John tells you the password, but has in fact not given up much secret. This is the case if he makes the case sensitivity truly random. Of course, once he sets his password, unless he has a great memory, he will need to write down the positions that are upper case. Otherwise, he will not be able to log back on. But that is a totally separate story.
The binomial angle
A good way to represent the passwords is to view each one as a 26-character string of U and L (U stands for upper case and L stands for lower case). Then the above two passwords (the one with 10 upper case letters and the one with 14 upper case letters) are represented as follows:
L L U L L L U L L L L L U U L L U U L U U L L U U L (10 U’s)
U U L U U L U U U U L L U U L U L U U L L L L U L L (14 U’s)
As discussed, there are 67,108,864 many such strings. We can also think of each such string as the record of a random experiment consisting of tossing a coin 26 times. We record a U when we get a head and record an L when the coin toss results in a tail. In fact, this is the kind of records that John would need to keep when he sets the password. Such a string would tell him which characters in the password are in upper case and which characters are in lower case. On the other hand, hacking the password would be essentially trying to pinpoint one such string out of 67,108,864 many possibilities.
We know 67,108,864 is a large number. Let’s further demonstrate the challenge. In each string, the number of U’s can range from 0 to 26. How many of the strings have 0 U’s? Precisely one (all letters are L). This would be what most people would try first (all the letters are lower case). How many of the strings have exactly 1 U? Thinking about it carefully, we should arrive at the conclusion that there are 26 possibilities (the single U can be in any of the 26 positions). So if the would be hacker knows there there is only one upper case letter, then it would be easy to break the password. How many of the strings have exactly 2 U’s? If you try to write out all the possible cases, it may take some effort. There are 325 possibilities. So just having two upper case letters in the password seems to make it something that is approaching a strong password. But the problem is that the two U’s may be guessed easily. John may put the upper case letters on his initials (if his name is John Smith, he may make J and S upper case), or in other obvious letters.
How many of the strings have exactly 3 U’s? This will be really hard to write out by hand. There are 2,600 many possibilities. Why stop at having just 3 upper case letters? It is clear that the more upper case letters used in the password, the stronger it is and the harder it is to crack.
How do we know the precise number of possibilities for a given , the number of U’s? The idea is that of choosing number of letters out of 26 letters.
The number of ways of choosing objects from a total of objects is denoted by the notation . Sometimes the notations , and are used. Regardless of the notation, the calculation is
The notation is the product of all the positive integers up to and including (this is called factorial). Thus , , , . To make the formula work correctly, we make .
The following gives the first several calculations in the 26-character password example.
If the desire is to see the patterns, the remaining calculations can be done by using software (or at least a hand held calculator). The following table shows the results.
The pattern is symmetrical. Having too few U’s or too many U’s produces weak passwords that may be easy to guess. Having 6 or 7 U’s seems to give strong passwords. Having half of the letters upper case (13 U’s) is the optimal, with the most possibilities (over 10 millions). Even if you are given partial information such as “half of the letters are in upper case”, you are still left with over 10 million possibilities to work with!
Dividing each of the above counts by 67,108,864 gives the relative weight (probability) of each case of having exactly U’s.
The cases of where add up to 67.3% of the 67,108,864 possibilities.
The binomial distribution
Another way to look at it is that in setting the password, John is performing a sequence of 26 independent Bernoulli trials. Here, each trial has two outcomes, a or A, b or B, c or C and so on. For example, the lower case or upper case can be determined by a coin toss. Let be the number of upper case letters in the 26-character password. Then the random variable has a binomial distribution with (26 Bernoulli trials) and the probability of success in each trial, which is the probability that a character is upper case, assuming that he determines the upper/lower case by a coin toss. The following is the probability function:
where . The quantity is the probability that the number of upper case letters is . Here, is the number of ways to choose letters out of 26 letters and is computed by the formula indicated earlier.
Since the upper/lower case is determined randomly, another way to state the probability function of the random variable is:
The expected value of this random variable is 13. This is the average number of upper case letters if the case is determined randomly. This obviously produces the most optimally strong password. If John determines the case not at random, the security may not be as strong or the would be hacker may be able to guess.
Stepping away from the 26-character password example, here’s the probability function of a binomial distribution in general.
This model describes the random experiment of running independent trials, where each trial has two outcomes (the technical term is Bernoulli trial). In each trial, the probability of one outcome (called success) is and the probability of the other outcome (called failure) is . The random variable counts the number of successes whenever such an experiment is performed. The probability gives the likelihood of achieving successes.
As an example, if John has a bias toward lower case letter, then the probability of success (upper case) may be (assuming that the random variable still counts the number of upper case letters). Then the average number of upper case letters in a randomly determined password is 26 x 0.4 = 10.4.
Interesting binomial distribution problems