[OT] programming question

bah@longitude.com bah at longitude.com
Thu Apr 26 00:20:32 BST 2007


> So what's the best way to randomly permute the order of the answers, store
> a small amount of state in a hidden field in the form, and reproduce the
> permutation back on the next call to the server, such that it can map back
> to the original answer order, without (too much) information leakage?

I don't know about "best", but how about adding a (different) random
number to each index while still keeping their ordinal value the same. 
Something like this:

  my $randMax = 1e8;
  my @indices = (1..10);
  for my $i (1.. at indices) {
    $indices[-$i] += int( $randMax / 2 + rand($randMax / 2) );
    $randMax = $indices[-$i] - $indices[-($i + 1)];
  }

  # yields, for example:
  # 2678665
  # 4838426
  # 5825823
  # 7871832
  # 13076201
  # 14728407
  # 15456229
  # 22235590
  # 41482818
  # 53271650

Maybe you'd want to pad the shorter values so it doesn't look like they're
shorter.  Like with random [A-F]s that you could easily strip out. ;-)

For added obfusecurity, you could then xor it with a secret key.

Ben


More information about the london.pm mailing list