Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rot13 for numbers

EDIT: Now a Major Motion Blog Post at http://messymatters.com/sealedbids

The idea of rot13 is to obscure text, for example to prevent spoilers. It's not meant to be cryptographically secure but to simply make sure that only people who are sure they want to read it will read it.

I'd like to do something similar for numbers, for an application involving sealed bids. Roughly I want to send someone my number and trust them to pick their own number, uninfluenced by mine, but then they should be able to reveal mine (purely client-side) when they're ready. They should not require further input from me or any third party.

(Added: Note the assumption that the recipient is being trusted not to cheat.)

It's not as simple as rot13 because certain numbers, like 1 and 2, will recur often enough that you might remember that, say, 34.2 is really 1.

Here's what I'm looking for specifically:

A function seal() that maps a real number to a real number (or a string). It should not be deterministic -- seal(7) should not map to the same thing every time. But the corresponding function unseal() should be deterministic -- unseal(seal(x)) should equal x for all x. I don't want seal or unseal to call any webservices or even get the system time (because I don't want to assume synchronized clocks). (Added: It's fine to assume that all bids will be less than some maximum, known to everyone, say a million.)

Sanity check:

> seal(7)
482.2382   # some random-seeming number or string.
> seal(7)
71.9217    # a completely different random-seeming number or string.
> unseal(seal(7))
7          # we always recover the original number by unsealing.
like image 525
dreeves Avatar asked Apr 30 '09 21:04

dreeves


People also ask

What is ROT13 code?

ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it in the alphabet. ROT13 is a special case of the Caesar cipher which was developed in ancient Rome.

Where is ROT13 used?

ROT13 was designed for use in Usenet newsgroups as a way to hide the content of postings. For example, a person could use ROT13 to encode an article he thinks may be offensive to some.

Is ROT13 encryption good?

Python3. Analysis: The ROT13 cipher is not very secure as it is just a special case of the Caesar cipher. The Caesar cipher can be broken by either frequency analysis or by just trying out all 25 keys whereas the ROT13 cipher can be broken by just shifting the letters 13 places. Therefore it has no practical use.

How do you do ROT13?

ROT13 = Rotate the string to be encrypted by 13 positions (modulo 26) in the alphabet of 26 characters. What is this? If you want to encrypt a string, shift each character forwards by 13 positions in the alphabet. If you move past the last character “z”, you start over at the first position in the alphabet “a”.


1 Answers

You can pack your number as a 4 byte float together with another random float into a double and send that. The client then just has to pick up the first four bytes. In python:

import struct, random
def seal(f):
   return struct.unpack("d",struct.pack("ff", f, random.random() ))[0]
def unseal(f):
   return struct.unpack("ff",struct.pack("d", f))[0]

>>> unseal( seal( 3))
3.0
>>> seal(3)
4.4533985422978706e-009
>>> seal(3)
9.0767582382536571e-010
like image 177
Jon Avatar answered Sep 26 '22 19:09

Jon