Re: mapping numbers to 'random' numbers and back



On 11 Aug 2006 13:15:03 GMT, JdV <usenet@xxxxxxx> wrote:

Hello,

I am looking for a simple algorithm to map small integers (4 digits,
0000-1000) to large random-looking numbers in a certain range (5 digits,
10000-99999). For example (just with some made-up numbers), 1 -> 62521,
2 -> 30162, and I need to be able to map the big numbers back to their
originals (30162 -> 2, etc).

Any tips on a method or algorithm to use for this ?

Thank you,

Some questions

1 Do you want to change the mapping every so often or is it permanent?

2 I assume you are doing this for security purposes. Do you want to
stop Aunt Edna reading it or do you want to stop Nasty Megacorp Inc
(with a lot of money) reading it?

If the mapping is permanent then a look-up table will do all that you
want.

If you want to change the mapping every so often then you will need
some sort of keyed mapping. One option is to take your four digits,
add a spurious digit for padding and shift each of the five digits by
some number mod 10.

For example:

Coding
Number: 1234
Add padding: 12345
Shift by: 81823

Result: 93168

(1+8 = 9, 2+1 = 3, 3+8 = 1, 4+2 = 6, 5+3 = 8, all mod 10)

Decoding
Cyphertext: 93168
Backshift by: 81823
Gives: 12345

(9-8 = 1, 3-1 = 2, 1-8 = 3, 6-2 = 4, 8-3 = 5, all mod 10)

Remove padding to give: 1234

How you generate the shift digits (81823) depends on who you are
hiding it from. For Aunt Edna then rand() is good enough, just pick a
key to reseed rand() so you get the same shift numbers for coding and
decoding. For Nasty Megacorp then you should use something
cryptographically secure, probably AES in CTR mode with the output
modified to produce results in the range 0-9 rather than 0-255. With
the second option you are going to have to get into all sorts of
cryptographic complications like nonces, securing the key and the
rest. That will give you some serious cryptographic work to do if you
go down that route.

rossum


.



Relevant Pages

  • Re: LCD controlling with comparators
    ... >> drive the digits. ... The rest of the pins are probably not connected to anything, ... There are 3 PIC pins used to shift data into the things and display it. ... You set a data bit either high or low, and then twiddle a clock ...
    (sci.electronics.basics)
  • Re: Another question about big floating point
    ... digits to the right of the radix point (so the numbers above have ... really add much cost to the addition/subtraction/etc. ... point when you use 2 as base for the exponent. ... shift plus the addition itself). ...
    (comp.programming)
  • Re: Round-Off Errors HP 48G
    ... Northing Easting ... the entire group of coordinates is "shifted" down to near the coordinate system origin for the purpose of the calculation. ... Now without the "shift", the answer is: ... You can see how the longer the list of high numbered coordinate values is, the larger a number \GSLIST will return, and with only 12 available digits you run out of digits pretty quickly. ...
    (comp.sys.hp48)
  • Creating a FIFO buffer with an array
    ... this data then needs to be put into a frame structure (matrix) ... what i essentially need is a way of dropping a dingle element from the start of the array, and adding one to the bottom. ... shift the data a single place and repeat tests. ... what is the easiest way to shift the digits like this? ...
    (comp.soft-sys.matlab)
  • When I select a tab to move, the unselected line above it also mov
    ... I've been having an occasional problem formatting columns of digits (baseball ... box scores) with tabs. ... When I select a certain digit to shift it to the left ...
    (microsoft.public.word.pagelayout)