0

I want code to render n bits with n + x bits, non-sequentially. I'd Google it but my Google-fu isn't working because I don't know the term for it.

For example, the input value in the first column (2 bits) might be encoded as any of the output values in the comma-delimited second column (4 bits) below:

 0  1,2,7,9
 1  3,8,12,13
 2  0,4,6,11
 3  5,10,14,15

My goal is to take a list of integer IDs, and transform them in a way they can still be used for persistent URLs, but that can't be iterated/enumerated sequentially, and where a client cannot determine programmatically if a URL in a search result set has been visited previously without visiting it again.

shannon
  • 8,664
  • 5
  • 44
  • 74

1 Answers1

1

I would term this process "encoding". You'll see something similar done to permit the use of communications channels that have special symbols that are not permitted in data. Examples: uuencoding and base64 encoding.

That said, you still need to (and appear at first blush to have) ensure that there is only one correct de-code; and accept the increase in size of the output (in the case above, the output will be double the size, bit-for-bit as the input).

I think you'd be better off encrypting the number with a cheap cypher + a constant secret key stored on your server(s), adding a random character or four at the end, and a cheap checksum, and simply reject any responses that don't have a valid checksum.

<encrypt(secret)>
    <integer>+<random nonsense>
</encrypt>
+
<checksum()>
    <integer>+<random nonsense>
</checksum>

Then decrypt the first part (remember, cheap == fast), validate the ciphertext using the checksum, throw off the random nonsense, and use the integer you stored.

There are probably some cryptographic no-no's here, but let's face it, the cost of this algorithm being broken is a touch on the low side.

Slartibartfast
  • 1,694
  • 9
  • 8
  • that's exactly what I was planning to do if I didn't find a pre-existing tool for this. http://crypto.stackexchange.com/questions/3393/encrypt-array-of-int-for-individual-retrieval , http://stackoverflow.com/questions/11706613/does-random-padding-an-int32-before-encryption-compromise-the-secret – shannon Aug 01 '12 at 09:18
  • note that a checksum isn't any more valuable than a constant value in my case, where I included it as part of the same encrypted block. – shannon Aug 01 '12 at 09:21
  • and yeah, while those spidering the member content would be competitors standing to profit, the profit wouldn't be so great as to hire a specialist to perform differential cryptanalysis on the URLs – shannon Aug 01 '12 at 09:23