title: Obfuscating an ID
body: <p>I'm looking for a way to encrypt/obfuscate an integer ID into another integer. More precisely, I need a function <code>int F(int x)</code>, so that</p>
  
  <ul>
  <li>x&lt;->F(x) is one-to-one correspondence (if x != y, F(x) != F(y))</li>
  <li>given F(x), it's easy to find out x - so F is not a hash function</li>
  <li>given x and F(x) it's hard/impossible to find out F(y), something like <code>x ^ 0x1234</code> won't work</li>
  </ul>
  
  <p>For clarity, I'm not looking for a strong encryption solution, it's only obfuscation. Imagine a web application with urls like <code>example.com/profile/1</code>, <code>example.com/profile/2</code> etc. The profiles themselves are not secret, but I'd like to prevent  casual voyeurs to view/fetch all profiles one after another, so I'd rather hide them behind something like <code>example.com/profile/23423</code>, <code>example.com/profile/80980234</code> etc. Although database-stored tokens can do the job quite easily, I'm curious if there's some simple math available for this.</p>
  
  <p>One important requirement I wasn't clear about is that results should look "random", that is, given a sequence <code>x,x+1,...,x+n</code> , <code>F(x),F(x+1)...F(x+n)</code> shouldn't form a progression of any kind.</p>