Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a solution inspired by Svante's answer.</p> <pre><code>M = 9999 # Upper bound on bid. seal(x) = M * randInt(9,99) + x unseal(x) = x % M </code></pre> <p>Sanity check:</p> <pre><code>&gt; seal(7) 716017 &gt; seal(7) 518497 &gt; unseal(seal(7)) 7 </code></pre> <p>This needs tweaking to allow negative bids though:</p> <pre><code>M = 9999 # Numbers between -M/2 and M/2 can be sealed. seal(x) = M * randInt(9,99) + x unseal(x) = m = x % M; if m &gt; M/2 return m - M else return m </code></pre> <p>A nice thing about this solution is how trivial it is for the recipient to decode -- just mod by 9999 (and if that's 5000 or more then it was a negative bid so subtract another 9999). It's also nice that the obscured bid will be at most 6 digits long. (This is plenty security for what I have in mind -- if the bids can possibly exceed $5k then I'd use a more secure method. Though of course the max bid in this method can be set as high as you want.)</p> <h3>Instructions for Lay Folk</h3> <p>Pick a number between 9 and 99 and multiply it by 9999, then add your bid. This will yield a 5 or 6-digit number that encodes your bid. To unseal it, divide by 9999, subtract the part to the left of the decimal point, then multiply by 9999. (This is known to children and mathematicians as "finding the remainder when dividing by 9999" or "mod'ing by 9999", respectively.)</p> <p>This works for nonnegative bids less than 9999 (if that's not enough, use 99999 or as many digits as you want). If you want to allow negative bids, then the magic 9999 number needs to be twice the biggest possible bid. And when decoding, if the result is greater than half of 9999, ie, 5000 or more, then subtract 9999 to get the actual (negative) bid.</p> <p>Again, note that this is on the honor system: there's nothing technically preventing you from unsealing the other person's number as soon as you see it.</p>
 

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