0
$\begingroup$

I have been trying to figure out how to generate the number of possible passwords given that the password must be eight characters long and requires at least two each of letters (non-case sensitive, so 26), digits (10), and certain special characters (6), and no character can be repeated. Currently, what I have is:

42!/34! - [36!/28! + 32!/24! + 16!/8!] + [26!/18! + 10!/2!] - [6*36!/29! + 10*32!/25! + 26*16!/9!] + ?

The last segment, where I should be accounting for any redundancies in the second exclusion, is where I have hit a dead-end. I believe that here I will have to insert a third exclusion since we now have overlap between all three, but I can't parse how to write this combination out. The best I can figure right now is:

+ [6*10*26!/20! + 6*26*10!/4! + 26*10*6!/0!]

But I am at a loss from there.

2 Answers 2

0

Let $S$ be the set of all eight-character strings using the $44$ allowed characters (with none repeated), $A$ those that have at least two letters, $B$ those that have at least two digits, $C$ those that have at least two special characters. You want $$|A \cap B \cap C| = |S| - |(A \cap B \cap C)^c| = |S| - |A^c \cup B^c \cup C^c| $$ (where $|\cdot|$ denotes the number of elements of a set). Inclusion-exclusion says $$ |A^c \cup B^c \cup C^c| = |A^c| + |B^c| + |C^c| - |A^c \cap B^c| - |A^c \cap C^c| - |B^c \cap C^c| + |A^c \cap B^c \cap C^c| $$ Now you just have to find the number of elements of each of those. Some are easy, e.g. $|A^c \cap B^c \cap C^c| = 0$ (if there are fewer than two letters, fewer than two digits and fewer than two special characters there's no way to get more than 3 characters).

0

The very first step you must take when applying inclusion-exclusion is to identify your overlapping sets. Essentially, the main reason to use inclusion-exclusion is if you have a situation where it is difficult to count all the good passwords directly, so instead yo count all the bad passwords and then subtract these from the total possible passwords.

$$\text{good passwords}=\text{total passwords}-\text{bad passwords}$$

The total passwords of length 8 are easy to count

$$\text{total passwords}=\binom{42}{8}8!$$

unfortunately the bad passwords of length 8 are not disjoint which makes them harder to count. In other words: a bad password may be bad in multiple ways e.g. A bad password may have fewer than 2 letters and digits or just fewer than 2 letters and so on. In fact, these conditions on numbers of characters of each type naturally define the sets for inclusion-exclusion. $$A_l=\text{the set of all passwords with }<2\text{ letters}\\A_d=\text{the set of all passwords with }<2\text{ digits}\\A_s=\text{the set of all passwords with }<2\text{ special characters}$$ We may imagine a Venn diagram with 3 sets

Hand drawn Venn Diagram

so that the total number of bad passwords is given by

$$\text{bad passwords}= |A_l|+|A_d|+|A_s|-\left(|A_l\cap A_d| +|A_l\cap A_s|+|A_d\cap A_s|\right)\\+|A_l\cap A_d\cap A_s|$$

Now we shall see how easy it is to calculate the cardinality of the sets and their intersections $$|A_l|=\left(\binom{26}{0}\binom{16}{8}+\binom{26}{1}\binom{16}{7}\right)8!\\ |A_d|=\left(\binom{10}{0}\binom{32}{8}+\binom{10}{1}\binom{32}{7}\right)8!\\ |A_s|=\left(\binom{6}{0}\binom{36}{8}+\binom{26}{1}\binom{36}{7}\right)8!\\ |A_l\cap A_d|=\left(\binom{26}{1}\binom{10}{1}\binom{6}{6}\right)8!\\ |A_l\cap A_s|=\left(\binom{26}{0}\binom{6}{0}\binom{10}{8}+\binom{26}{1}\binom{6}{0}\binom{10}{7}+\binom{26}{0}\binom{6}{1}\binom{10}{7}+\binom{26}{1}\binom{6}{1}\binom{10}{6}\right)8!\\ |A_d\cap A_s|=\left(\binom{10}{0}\binom{6}{0}\binom{26}{8}+\binom{10}{1}\binom{6}{0}\binom{26}{7}+\binom{10}{0}\binom{6}{1}\binom{26}{7}+\binom{10}{1}\binom{6}{1}\binom{26}{6}\right)8!\\ |A_l\cap A_d\cap A_s|=0\\$$ The counts above are achieved by considering all combinations in which we may choose $<2$ of each type of character, clearly the intersection of all 3 sets is empty because there are no 8 character passwords with less than 2 of each of the 3 character types, at most such a password has 3 characters. These terms may all be evaluated a plugged in to our first equation.