Symmetric Bijective Algorithm for Integers

后端 未结 11 891
甜味超标
甜味超标 2020-12-01 03:33

I need an algorithm that can do a one-to-one mapping (ie. no collision) of a 32-bit signed integer onto another 32-bit signed integer.

My real concern is enough entr

11条回答
  •  无人及你
    2020-12-01 04:16

    I will try to explain my solution to this on a much simpler example, which then can be easily extended for your large one.

    Say i have a 4 bit number. There are 16 distinct values. Look at it as if it was a four dimensional cube:
    (source: ams.org)
    .

    Every vertex represents one of those numbers, every bit represents one dimension. So its basicaly XYZW, where each of the dimensions can have only values 0 or 1. Now imagine you use a different order of dimensions. For example XZYW. Each of the vertices now changed its number!

    You can do this for any number of dimensions, just permute those dimensions. If security is not your concern this could be a nice fast solution for you. On the other hand, i dont know if the output will be "obscure" enough for your needs and certainly after a large amount of mapping done, the mapping can be reversed (which may be an advantage or disadvantage, depending on your needs.)

提交回复
热议问题