Re: mapping numbers to 'random' numbers and back
- From: rossum <rossum48@xxxxxxxxxxxx>
- Date: Fri, 11 Aug 2006 23:17:33 +0100
On 11 Aug 2006 13:15:03 GMT, JdV <usenet@xxxxxxx> wrote:
Hello,Some questions
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,
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
.
- References:
- Prev by Date: Re: Key establishment question
- Next by Date: Re: random numbers
- Previous by thread: Re: mapping numbers to 'random' numbers and back
- Next by thread: Key establishment question
- Index(es):
Relevant Pages
|