Hi,
I am trying to take two pieces of unique information and encode them into a 9 digit number with a static seed. I also need the ability to decode it given the proper seed. The two pieces of information are..
1) An IP addresss
2) A 9 digit session id
I thought about first base 10 encoding the IP address using the following code...
unpack "N", pack "C4", split /\./, "64.58.79.230"
and then just appending the 9 digit session id.
However, due to project restrictions, I need the final number to be a unique result, no more than 9 digits, and it must be a non-floating point positive integer. Is there some cipher or mathematical function that I could use to get this result? Speed is also an issue so the fastest algorithm would be preferred.
An example function would be...
$uniq_result = encode("static_seed","64.58.79.230","542158235");
($IP,$sessionid) = decode("static_seed",$uniq_result);
Security is not an issue really, so a seed might not even be necessary. Also, the ability to encode is much more important than the ability to decode. So if encoding without the ability to decode is all I can get, than I'll make do. As long as no unique combination of IP address and sessionid will produce the same 9 digit number, I'm ok.
Any help would be greatly appreciated. I've been racking my brain trying to come up with a solution.
Thanks
-scrill
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.