Imagine a value, say '1234'. I want to map that value to an other value, say 'abcd'. The constrains:
- The length of the target value is equal to the start value
- The mapping should be unique. E.g. 1234 should only map to abcd and viseversa
- The mapping process should be (very) difficult to guess. E.g. multiplying by 2 does count
- The mapping should be reversible
- The start value is an integer
- The target value can be of any type
This should be a basic algorithm, eventually I'll write it in Ruby but that is of no concern here.
I was thinking along the following lines:
SECRET = 1234
def to(int)
SECRET + int * 2
end
def fro(int)
(int - SECRET) / 2
end
Obviously this violates constrains 1 and 3.
The eventual goal is to anonymize records in my database. I might be over thinking this.