views:

217

answers:

2

I need to add the URL of a 3rd-party website to a url, but I'd like to compress/obfuscate the host part. Are there any algorithms I can use which will hash the url, but also allow un-hashing?

For example; the url is http://www.twitter.com/myusername. What I'm serving currently (as a html link) is http://mysite.net/bounce/www.twitter.com/username. What I'd like to serve is something like http://mysite.net/bounce/X5nsSkdWfA/username, and have the bounce script decode |^/bounce/(.*)/| back to www.twitter.com.

I'd like to do this without storing the hash anywhere.

Suggestions?

+4  A: 

You can use, for instance, ROT13 for obfuscating ;-)

$ echo twitter.com | rot13
gjvggre.pbz

Then you can use base64

$ echo twitter.com | base64
dHdpdHRlci5jb20K

Naturally, they don't compress. You can come with something yourself for squeezing a few bits out of it.

Michael Krelin - hacker
The ratio is 1:1 for Rot13 and 3:4 for Base64.
Gumbo
Gumbo, right, base64 obfuscates better. But then you can roll your own encoder, knowing that host part is case insensitive (1 bit off) and generally can only use a very limited set of characters (too lazy to calculate bit savings).
Michael Krelin - hacker
Thanks - a little ROT13 with some other magic and it works like a charm!
digitala
A: 

you can use technique exist in this tut..

BUILDING A URL SHORTENER

you can use the function to shortern url and convert it back, by extracting it from url.

assaqqaf
Won't work. I need to do this without storing the hash; that method stores the hash in the DB.
digitala