in reply to integer encoder/decoder
You cannot guarantee no collisions since one of your input spaces is the 9 digit number and your output space is the same size. You can probably code to reduce the possibility. If you could use another base like 64 then your output space is larger than your input space.
Specifically your input space is basically a 30 bit quantity + a 32 bit quantity which you want to store uniquely in a 30 bit space. For each value in the output, there are 2**32 inputs which will give you that output.
If you could use base64 then you could get a 62 bit quantity SID.IP into 9 character places.
If you used for example Digest::MD5 you can get an almost certainly unique quantity base16 in 32 bytes or base64 in 22 bytes. This uses an existing module implementing a strong digest algorithm which is the math problem you are wanting to solve.
In summary you can make up a program to map the ip address into the existing session id and you can work to avoid collisions but ultimately the space is too small to never have a collision
If you can throw the unique ids away after a time then by using time generated as a small factor you could probably get a system which would not be likely to collide for the lifetime of the session id. This is the only solution that seems to not have a collision hazard but the larger the time interval the more likely a collision.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: integer encoder/decoder
by Anonymous Monk on Mar 13, 2003 at 19:15 UTC |