I’m looking for a simple way to translate long to String and back in a way that will “hide” the long value.
I’d prefer to avoid adding another .jar to the project for this feature.
It does not have to be a hard-to-crack encryption, just to look random to the inexperienced eye.
Addition:
My purpose here is to attach a counter value (of type long) to URLs as a tracking parameter without the users aware of the counter’s value (sort of like tinyURL’s hash), so that the servlet will know the value of the counter when the URL is clicked.
Thanks
If
then
So, you can “encrypt” some 32-bit number by multiplying it by X, and then later “decrypt” by multiplying by Y. All you need is to find some non-trivial X and Y that satisfy the condition.
For instance, (X, Y) = (3766475841, 1614427073), or (699185821, 3766459317). I just found these with a simple brute force program.
Once you have A*X you can encode it using Base-64 or hexadecimal or some similar scheme in the URL. I’d suggest Base64 because it takes up less space and looks fairly “random”.