Simple and very fast encoder-decoder
I will explain my need with an example;
www.domain.com/photo.jsp?id=23
here id is 23 and people can try every photo by incresing or decreasing the id number. I want to encode the id's while printing the id to screen as url and will decode everytime when i get the request from user.
So i need a very fast and simple logic of encode & decode. I have tested base64 at java but everyone knows the algortihm. Is there any other simple algorithm that i can generate on my own?
What do you advice to me except changing my database and search with hex keys?
[586 byte] By [
netsonicca] at [2007-11-27 11:33:13]

So you want to prevent the id from appearing in the url? why not just use a POST instead of a GET?
~Tim
Hex keys?
I advise to check the dereferrer field in the request instead. I suppose an edited address line won't lead to a request containing your website as a dereferrer, unlike a click on "next".
Or use a POST. Or just don't bother. Or generate UUIDs for each image.
what's so secret about those photos anyway that you don't want people to see them without clicking on a link somewhere on your site?
Or are you afraid your users will bypass the megabytes of flashing advertising banners you present them with (a usual reason to want to hide things like this).
why dont u support the way i am doing?
searching at database with integer primary index key will be faster than searching with hex keys...
so if i use a very fast decoder encoder i think it will be no problem about processing time.
And i dont want to hide any link because the users may share the url's that they enjoy directly like youtube links.
So will anyone make clear the ideas i wrote above? Any unique fast encoder decoder?
thank you
> what's so secret about those photos anyway that you
> don't want people to see them without clicking on a
> link somewhere on your site?
> Or are you afraid your users will bypass the
> megabytes of flashing advertising banners you present
> them with (a usual reason to want to hide things like
> this).
nothing is secret but i want to force users to follow my links at the web site! believe me its strictly needed on a photo web site... there are too much reasons.
> nothing is secret but i want to force users to follow
> my links at the web site!
I think "use POST" was mentioned twice.
> believe me its strictly
> needed on a photo web site... there are too much
> reasons.
I can't think of one.
dwga at 2007-7-29 16:50:02 >

its ok but if i POST something my urls are hidden but this time users cant copy paste the links to share directly like youtube links:
The exact url with parameter must be written on the browser.
Well, then you need some way to come up with some basic "encrpytion algorithm". Like multiply by 5427 and add 18.
> > believe me its strictly
> > needed on a photo web site... there are too much
> > reasons.
>
> I can't think of one.
1)when ids are sequantial on db users can get the idea which after or before this photo is uploaded
2)when you see the normal integer numbers on ids you can remember it easily and edit the link by hand and see whats going on...
3)When u see user_id is=1 u can understand easily that he is an admin or one of the first member of website
4)when u try the maximum photo id or user id every user can understand how many user or photos are there in website
there are lots of things like above... They may be not that valueble for everyone but i think this have to be.
thankss... finally someone came to real point:)
as i know most of random algorithms made with mod operation but at the same time the generated randoms must be unique and can be decoded to original...
i thought about multiplying and adding something but is this better than base64 about speed... I dont know how to test the performance...
thanks
> i thought about multiplying and adding something but
> is this better than base64 about speed... I dont know
> how to test the performance...
Are you kidding?
And I already suggested using an UUID, you could generate and store that with the image and index that or use it as a key right away... would be even faster because it doesn't need repetitive encoding/decoding. Although you can do the same approach with that simple math.
Fastest code is the one that's never executed.
thank you then i will try these and test performance and not kidding dont know how to taste it.