Obscure / encrypt an order number as another number: symmetrical, “random” appearance?

后端 未结 7 516
长情又很酷
长情又很酷 2020-12-13 02:44

Client has an simple increasing order number (1, 2, 3...). He wants end-users to receive an 8- or 9- digit (digits only -- no characters) \"random\" number. Obviously, this

7条回答
  •  醉酒成梦
    2020-12-13 02:59

    I saw this rather late, (!) hence my rather belated response. It may be useful to others coming along later.

    You said: "My third thought was "eh, just encrypt the darn thing," but if I use a stock encryption library, I'd have to post-process it to get the 8-or-9 digits only requirement."

    That is correct. Encryption is reversible and guaranteed to be unique for a given input. As you point out, most standard encryptions do not have the right block size. There is one however, Hasty Pudding Cipher which can have any block size from 1 bit upwards.

    Alternatively you can write your own. Given that you don't need something the NSA can't crack, then you can construct a simple Feistel cipher to meet your needs.

提交回复
热议问题