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
    Thats an interesting idea. You certainly have more of a grasp on it than I do. Unfortunately, my knowledge of base64 and even base10 encoding is extremely limited. The unmap call in my original post was used from an example in another node.

    I looked into Digest::MD5, but found that the smallest result that could be produced from any of the digest functions was 16 bytes from binary digest. The other prduced too many characters.

    What I really need is an example of exactly how to do this, if it's possible. My experience with map/unmap is sparse.

    Could you post an example? Don't get me wrong, I'm not looking for a handout, but an example with an explanation would help me learn.

    Thanks