I need some pointers or a practical example on how to encrypt an int to another int, and a secret key would be required to decrypt the value.
Something like:
encrypt(1, "secret key") == 67123571122
decrypt(67123571122, "secret key") == 1
This guy asks pretty much the same question: http://stackoverflow.com/questions/3131193/symmetric-bijective-algorithm-for-integers
however me being a total encryption "n00b" I would like some more practical examples, in python if possible.
I understand I need to use some kind of block cipher, but I'm pretty lost on the part about keeping the encrypted result still be numeric and somewhat short (maybe a long instead of an int)
Any pointers? Thanks
UPDATE-
Why do I want to do this?
I have a web service where each "object" gets a URL, e.g.:
example.com/thing/123456/
Right now, those IDs are sequential. I want to hide the fact that they're sequential (database IDs).
The stuff on those pages is not "top secret" or anything like that, but it shouldn't be as easy for someone to snoop in some other random' object as just incrementing that ID in the URL.
So with some kind of two-way numeric encryption, the URL IDs will not be sequential at all, and it would take someone quite a bit of time to find more of these objects. (Additionally, requests are throttled)
And the only reason I want to keep this numeric instead of an arbitrary string is so that the change is a total drop-in replacement, and things will just work without any other code changes.
Also, I can't just generate new random database IDs. I have to handle this encrypt/decrypt in the application.