# How many 5 character passwords are possible if each password must contain at least one special character?

Suppose a system requires you to choose a 5 character password. Only the digits 0-9, lowercase letters, and 3 special characters are allowed to be used, and no character is allowed to be repeated. If at least 1 special character is also required, how many possible 5 character passwords can there be?

So I know for this I have to use combinations and permutations but I'm not sure how to approach multiple options like this. I'll try to write out my thought process: (SC = special character)

a (1 SC) = nCr(3, 1) * nPr(36, 4) * nPr(5, 1)

(choose 1 SC out of 3) * (choose 4 out of 36 digits or letters, no repetition) * (choose 1 placement in the 5 characters for the SC)

b (2 SCs) = nCr(3, 2) * nPr(36, 3) * nPr(5, 2)

(choose 2 SC out of 3) * (choose 3 out of 36 digits or letters, no repetition) * (choose 2 placements in the 5 characters for the SCs)

c (3 SCs) = nCr(3, 3) * nPr(36, 2) * nPr(5, 3)

(choose 3 SC out of 3) * (choose 2 out of 36 digits or letters, no repetition) * (choose 3 placements in the 5 characters for the SCs)

a + b + c = answer

Am I on the right track here? Any feedback is appreciated!

• One way is to find the number of passwords in total with no repeats and subtract the number of passwords with no repeats and no special characters Oct 7, 2021 at 17:42
• You have $$3\cdot 5$$ possibilities to choose the special character and its position. Letting $$n=\text{Number of allowed characters} = 10+26+3,$$ then you have $(n-1)(n-2)(n-3)(n-4)$ possibilities left. Oct 7, 2021 at 17:42
• @Henry ohhh so nPr(39, 5) - nPr(36,5), I can't believe I didn't think of that! Oct 7, 2021 at 17:50

$$N$$ - number of all characters (specials included)
$$n$$ - number of non-special characters
number of all possible 5 letter words from all possible characters $${N\choose 5} 5!$$
number of all possible 5 letter words from non-special characters only $${n\choose5} 5!$$ $$\text{Answer: }{N\choose5} 5! - {n \choose 5} 5!$$

• "no character is allowed to be repeated" Oct 7, 2021 at 17:54
• Thanks for the comment, changed it. Oct 7, 2021 at 18:00

$$\mathbf{\text{NOTE=}}$$ I give this answer for showing what you can do for more advanced questions .

I see that you have a problem with how many number of special character , digit and letters must be and the order of them in password. Hence , in your approach , you are missing very important thing , it is the location of different types of integrents.

What i meant by "the location of different types of integrents." is that the password $$L-D-SC-SC-D$$ is different from $$D-L-L-SC-L$$ where $$L,D,SC$$ means letter, digit , special character , respectively.

Then , how we handle this situation ? We can calculate the situations exhaustively such that $$1$$ SC , $$1$$ D , and $$3$$ L etc. As you see ,this is very cumbersome even for $$n=5$$. Then , we need a shortcut to get rid of this torturus process .

So , who is our hero to save us from this swamp ? The answer is exponential generating functions.

Lets say that the exponential generating function of special characters is $$\bigg(x + \frac{x^2}{2!} + \frac{x^3}{3!} \bigg)$$ we start from $$x$$ and end in $$x^3$$ , because the repetition is not allowed and it must appear.

Now , we should add some coefficients to this exponential generating function , the coefficients will be the permutatitons of the characters ,according to the exponential such that $$\bigg(P(3,1)x + P(3,2)\frac{x^2}{2!} + P(3,3)\frac{x^3}{3!} \bigg)=\bigg(3x + 3{x^2} + {x^3} \bigg)$$

Lets say that the exponential generating function of letters is $$\bigg(1+x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!}\bigg)$$ We start form $$x^0 =1$$ and end up $$x^4$$ , because there is not any restriction over it. Now , place the coefficients to find the permutatitons according to the exponential such that $$\bigg(P(26,0)1+ P(26,1)x + P(26,2)\frac{x^2}{2!} + P(26,3)\frac{x^3}{3!} + P(26,4)\frac{x^4}{4!}\bigg)$$

It is equal to $$\bigg(1+ 26x + 325{x^2} + 2600{x^3} + 14950{x^4}\bigg)$$

Lets say that the exponential generating function of digits is $$\bigg(1+x + \frac{x^2}{2!} + \frac{x^3}{3!} + \frac{x^4}{4!}\bigg)$$ We start form $$x^0 =1$$ and end up $$x^4$$ , because there is not any restriction over it. Now , place the coefficients to find the permutatitons according to the exponential such that $$\bigg(P(10,0)1+ P(10,1)x + P(10,2)\frac{x^2}{2!} + P(10,3)\frac{x^3}{3!} + P(10,4)\frac{x^4}{4!}\bigg)$$

It is equal to $$\bigg(1+ 10x + 45{x^2} + 120{x^3} + 210{x^4}\bigg)$$

Now , find the coefficient of $$x^5$$ in the expansion of $$\bigg(3x + 3{x^2} + {x^3} \bigg) \times \bigg(1+ 26x + 325{x^2} + 2600{x^3} + 14950{x^4}\bigg) \times \bigg(1+ 10x + 45{x^2} + 120{x^3} + 210{x^4}\bigg)$$

After that , multiply it by $$5!$$ , it is the result.

So , $$5! \times 198765 =23,851,800$$