Calculating all Possible Keys vs All possible numbers confusion

1.6k Views Asked by At

With a key of length n bits, there are 2n possible keys.

eg: 128-bit key length will have 2128 possible keys

But when calculating every possible n digit number, there are n!(nth factorial) possible keys.

eg: There will be 10! possible 10 digit numbers

Then why not calculate every 128 bit key with 128! (nth factorial) method ?

Pardon my maths. Thanks

2

There are 2 best solutions below

3
On BEST ANSWER

I think you are conflating a couple of ideas. First, the 128-bit number is a string of 128 characters, each character is either $0$ or $1$. Since you have 2 choices for each element of the string there are $2\cdot 2\cdot 2... 2=2^{128}$ strings.

For a decimal number with 10 digits, there are 10 choices for each digit in the string. If there are $k$ decimal digits in the string, then there are $10^{k}$ different strings. $10!$ would be the number of length 10 strings of decimal numbers with no repeats, i.e. you could not have the number 1111111111.

0
On

There are $2!=2$ ways of writing binary such that no digits are repeated, namely $01_2$ and $10_2$, although using modern computer notation the first would be disallowed, as leading zeroes are trimmed.

Similarly $0123456789_{10}$ doesn't count in base $10$, but $1023456789_{10}$ does count.

There are $b!$ ways of doing this in base $b$. Ignoring leading zeroes returns $(b-1)(b-1)!$ results.

Just using the available digits in base $b$, allowing those numbers with leading zeroes, there are $b^k$ variants for a $k$-length number. Ignoring leading zeroes gives $b^{k-1}$ versions.