Encrypt/Compress a 17 digit number to a smalller 9(or less) digit number.

650 Views Asked by At

I have a unsigned long integer(8 bytes) which is guaranteed to be of 17 digits and i want it to store in int(4 bytes) which is of 9 digits at max. Basically i want to encrypt or compress the number so that i could retrieve the number without any loss of information.

1

There are 1 best solutions below

0
On

There are $9 \times 10^{16}$ different decimal integers with $17$ decimal digits.

There are $2^{4\times 8} \lt 4.3 \times 10^9$ possible values of four bytes, a much smaller cardinality.

So you cannot find a $1-1$ injection from the former set to the latter.