Note that there are some explanatory texts on larger screens.

plurals
  1. POSymmetric integer to integer encryption
    primarykey
    data
    text
    <p>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.</p> <p>Something like:</p> <pre><code>encrypt(1, "secret key") == 67123571122 decrypt(67123571122, "secret key") == 1 </code></pre> <p>This guy asks pretty much the same question: <a href="https://stackoverflow.com/questions/3131193/symmetric-bijective-algorithm-for-integers">Symmetric Bijective Algorithm for Integers</a><br> however me being a total encryption "n00b" I would like some more practical examples, in python if possible.</p> <p>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)</p> <p>Any pointers? Thanks</p> <p>UPDATE- <strong>Why do I want to do this?</strong><br> I have a web service where each "object" gets a URL, e.g.: <code>example.com/thing/123456/</code></p> <p>Right now, those IDs are sequential. I want to hide the fact that they're sequential (database IDs).</p> <p>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. </p> <p>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)</p> <p>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.</p> <p>Also, I can't just generate new random database IDs. I have to handle this encrypt/decrypt in the application.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload