A user must choose $ n $ characters password using:

  1. uppercase letters $ A-Z (size=26)$
  2. lowercase letters $ a-z (size=26)$
  3. digits $ 0-9 (size=10)$

Each password must contain at least an uppercase and a digit.

What should be the formula to calculate number of valid passwords of size $ n $, give $ n >= 1$ ?

I have calculated it to be:

Uppercase x Digit x combination of all 3 types = $ 26\times10\times(26\times26 \times10)^{n}$

  • $\begingroup$ Hint: How many passwords of size 1 are there? What does your formula say? $\endgroup$ – Mees de Vries Nov 27 '16 at 15:43
  • $\begingroup$ hmm it should be 0 but the formula gives a rather large number $\endgroup$ – KillerKidz Nov 27 '16 at 15:45

The easiest way to do this is probably inclusion-exclusion. There are $62^n$ strings of length $n$ using the characters provided. There are $36^n$ such strings without an uppercase letter, and $52^n$ such strings without a lowercase letter, and $26^n$ such strings without either.

Thus, the total number of valid passwords of length $n$ is $$ 62^n - 36^n - 52^n + 26^n, $$ where you add the number of strings without either back in, because you have subtracted it twice.

  • $\begingroup$ why is the case for without upper case 36^n? Do I have to remove the strings without lowercase since an its not required for a password to contain any lowercase characters? $\endgroup$ – KillerKidz Nov 27 '16 at 15:52
  • $\begingroup$ There are 36 characters which are not uppercase letters: 26 lowercase letters and 10 digits. $\endgroup$ – Mees de Vries Nov 27 '16 at 15:55

The answer should be calculated as all possible combinations $(26+26+10)^n$, minus the incorrect ones (no uppercase, no digits).

Because of inclusion/exclusion, you have to ADD (you subtracted twice) all solutions that have no uppercase and no digits (all lowercase).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.