Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Suppose we are assigning records an unsigned integer ID from a N-bit space (say 32-bit) in a sequential manner. Is there a way we can code this ID before showing it to the public such that someone can't guess the next ID in the sequence. It should be two-way, such that given the coded int, we can determine the original ID and 1:1 such that every ID has exactly one corresponding coded int (ideally of the same bit-length).

This doesn't need to hold up to any kind of brute force attack, but should be non-obvious to viewers if two coded integers represent IDs close together or far apart.

Any ideas? The simpler the implementation the better.

share|improve this question
Either use a 32 bit blockcipher like Skip32 or use proper format preserving encryption (tricky to implement). – CodesInChaos Mar 21 '15 at 17:09
up vote 2 down vote accepted

A few approaches:

  • Generic format preserving encryption. For example AES in FFX mode.

    The downsides of this approach are complexity and performance.

  • Block-ciphers with small (typically 32 bit) blocks.

    • Skip32 derived from Skipjack
    • ipcrypt (very recent, no security analysis so far)

    The downside of this approach is that these ciphers aren't very popular and probably haven't seen much analysis.

  • Shuffling algorithms like thorp shuffle of swap-or-not.

share|improve this answer
I first thought that ipcrypt was not very interesting, I could not even find a paper on it. But a quick search found that the author is Jean-Philippe Aumasson of Blake(2) fame, and based on SipHash. Reputable, but indeed, no security analysis and no paper. – Maarten Bodewes Apr 2 '15 at 19:37
Skip32 is EXACTLY what I am looking for. I quickly found a javascript implementation at which can be quite literally dropped into my existing application. Thanks! – sstur Apr 3 '15 at 16:23

swap-or-not seems perfect for your use case.

share|improve this answer
Indeed. Or any block cipher with a small block, as common in Format-Preserving Encryption. I have re-tagged the question accordingly. Following that tag will lead to many related questions with good answers. – fgrieu Mar 21 '15 at 5:51
Thank you Ricky I will read that article and explore other format-preserving encryption questions mentioned by @fgrieu. Thanks! – sstur Mar 21 '15 at 17:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.