0

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}$

KillerKidz
  • 317
  • 2
  • 12

2 Answers2

1

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.

Mees de Vries
  • 26,947
  • 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? – KillerKidz Nov 27 '16 at 15:52
  • There are 36 characters which are not uppercase letters: 26 lowercase letters and 10 digits. – Mees de Vries Nov 27 '16 at 15:55
1

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).

Pieter21
  • 3,475