You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by nicolas de loof <ni...@apache.org> on 2009/01/29 15:18:32 UTC

[Math] looking for a "dispersion" function

Hi,
I have to generate some alpanumeric ID based on a database sequence.
The idea is to generate some ID that will not indicate the ordering in the
database, or it's amount of data

It's easy to convert some long to a String using a 26 based number
conversion.
I now need some mathematical function to "disperse" my sequenc-generated ID
into the numbers space.

Any suggestion ?

Nicolas

[id] Re: [Math] looking for a "dispersion" function

Posted by Phil Steitz <ph...@gmail.com>.
Ted Dunning wrote:
> Regarding the inversion, btw, here is the answer:
>
> http://en.wikipedia.org/wiki/Modular_multiplicative_inverse
>
> On Fri, Jan 30, 2009 at 1:33 AM, nicolas de loof
> <ni...@gmail.com>wrote:
>
>   
>> Works fine, as I don't need security but obfuscation
>>
>> Great algorithm ! Thanks a lot
>>
>>
>>     
This would be good generator to add to the sandbox-languishing [id] 
component.  It would be great to promote and release that component.  
What stands in the way is verifying (or just dropping) the GUID 
generators and some committer/RM energy.

Phil

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [Math] looking for a "dispersion" function

Posted by Ted Dunning <te...@gmail.com>.
Regarding the inversion, btw, here is the answer:

http://en.wikipedia.org/wiki/Modular_multiplicative_inverse

On Fri, Jan 30, 2009 at 1:33 AM, nicolas de loof
<ni...@gmail.com>wrote:

> Works fine, as I don't need security but obfuscation
>
> Great algorithm ! Thanks a lot
>
>
>
>
> On Thu, Jan 29, 2009 at 6:25 PM, Ted Dunning <te...@gmail.com>
> wrote:
>
> > Multiply by a reasonably large prime number p and reduce modulo 2^n where
> n
> > is big enough.
> >
> > Since p and 2^n are relatively prime, this method will permute the
> numbers
> > in [0, 2^n).  You can compute compute q such that p q = 1 mod 2^n pretty
> > easily which lets you invert this mapping easily.
> >
> > This is definitely not cryptographic quality, but it works very well.  If
> > somebody has access to nearly consecutive mapped numbers and they know
> your
> > method then they can invert it relatively easily.  If they have access to
> > just a few numbers that are not near each other in the sequence it would
> be
> > difficult to reverse engineer.
> >
> > If you want higher security, just use one of the standard ciphers built
> > into
> > java such as AES (or even DES).  It is just a few lines of code to
> encrypt
> > a
> > 64 bit number.  Make sure you aren't using any kind of cipher feedback.
> > Speed is not super high, but is plenty fast compared to any disk
> operation
> > so it should be fine in the face of database delays.
> >
> >
> > On Thu, Jan 29, 2009 at 6:18 AM, nicolas de loof <ni...@apache.org>
> > wrote:
> >
> > > Hi,
> > > I have to generate some alpanumeric ID based on a database sequence.
> > > The idea is to generate some ID that will not indicate the ordering in
> > the
> > > database, or it's amount of data
> > >
> > > It's easy to convert some long to a String using a 26 based number
> > > conversion.
> > > I now need some mathematical function to "disperse" my
> sequenc-generated
> > ID
> > > into the numbers space.
> > >
> > > Any suggestion ?
> > >
> > > Nicolas
> > >
> >
> >
> >
> > --
> > Ted Dunning, CTO
> > DeepDyve
> > 4600 Bohannon Drive, Suite 220
> > Menlo Park, CA 94025
> > www.deepdyve.com
> > 650-324-0110, ext. 738
> > 858-414-0013 (m)
> >
>



-- 
Ted Dunning, CTO
DeepDyve
4600 Bohannon Drive, Suite 220
Menlo Park, CA 94025
www.deepdyve.com
650-324-0110, ext. 738
858-414-0013 (m)

Re: [Math] looking for a "dispersion" function

Posted by nicolas de loof <ni...@gmail.com>.
Works fine, as I don't need security but obfuscation

Great algorithm ! Thanks a lot




On Thu, Jan 29, 2009 at 6:25 PM, Ted Dunning <te...@gmail.com> wrote:

> Multiply by a reasonably large prime number p and reduce modulo 2^n where n
> is big enough.
>
> Since p and 2^n are relatively prime, this method will permute the numbers
> in [0, 2^n).  You can compute compute q such that p q = 1 mod 2^n pretty
> easily which lets you invert this mapping easily.
>
> This is definitely not cryptographic quality, but it works very well.  If
> somebody has access to nearly consecutive mapped numbers and they know your
> method then they can invert it relatively easily.  If they have access to
> just a few numbers that are not near each other in the sequence it would be
> difficult to reverse engineer.
>
> If you want higher security, just use one of the standard ciphers built
> into
> java such as AES (or even DES).  It is just a few lines of code to encrypt
> a
> 64 bit number.  Make sure you aren't using any kind of cipher feedback.
> Speed is not super high, but is plenty fast compared to any disk operation
> so it should be fine in the face of database delays.
>
>
> On Thu, Jan 29, 2009 at 6:18 AM, nicolas de loof <ni...@apache.org>
> wrote:
>
> > Hi,
> > I have to generate some alpanumeric ID based on a database sequence.
> > The idea is to generate some ID that will not indicate the ordering in
> the
> > database, or it's amount of data
> >
> > It's easy to convert some long to a String using a 26 based number
> > conversion.
> > I now need some mathematical function to "disperse" my sequenc-generated
> ID
> > into the numbers space.
> >
> > Any suggestion ?
> >
> > Nicolas
> >
>
>
>
> --
> Ted Dunning, CTO
> DeepDyve
> 4600 Bohannon Drive, Suite 220
> Menlo Park, CA 94025
> www.deepdyve.com
> 650-324-0110, ext. 738
> 858-414-0013 (m)
>

Re: [Math] looking for a "dispersion" function

Posted by Ted Dunning <te...@gmail.com>.
Multiply by a reasonably large prime number p and reduce modulo 2^n where n
is big enough.

Since p and 2^n are relatively prime, this method will permute the numbers
in [0, 2^n).  You can compute compute q such that p q = 1 mod 2^n pretty
easily which lets you invert this mapping easily.

This is definitely not cryptographic quality, but it works very well.  If
somebody has access to nearly consecutive mapped numbers and they know your
method then they can invert it relatively easily.  If they have access to
just a few numbers that are not near each other in the sequence it would be
difficult to reverse engineer.

If you want higher security, just use one of the standard ciphers built into
java such as AES (or even DES).  It is just a few lines of code to encrypt a
64 bit number.  Make sure you aren't using any kind of cipher feedback.
Speed is not super high, but is plenty fast compared to any disk operation
so it should be fine in the face of database delays.


On Thu, Jan 29, 2009 at 6:18 AM, nicolas de loof <ni...@apache.org> wrote:

> Hi,
> I have to generate some alpanumeric ID based on a database sequence.
> The idea is to generate some ID that will not indicate the ordering in the
> database, or it's amount of data
>
> It's easy to convert some long to a String using a 26 based number
> conversion.
> I now need some mathematical function to "disperse" my sequenc-generated ID
> into the numbers space.
>
> Any suggestion ?
>
> Nicolas
>



-- 
Ted Dunning, CTO
DeepDyve
4600 Bohannon Drive, Suite 220
Menlo Park, CA 94025
www.deepdyve.com
650-324-0110, ext. 738
858-414-0013 (m)