"Scrambling" an integer on the fly: what's it called?

I want to scramble "on the fly" integers (between 0 and 100,000) into some 15-byte Strings or 15-byte numbers (or shorter).

I have no doubt that I could come up with a simple mathematical algorithm, but surely this method must exist already in some library. Because I don't know how to call what I am looking for, I have so far failed to find what I wanted.

Does anyone have references?

Or even just the "official" name of that kind of method would help me in my research!

Criteria:

* it has to be VERY fast, both to scramble and to unscramble.

* it doesn't have to be top level of security

(Background: the original integers are reference IDs and they come as a sequence: ..., 542, 543, 544, ... It's important to prevent someone from gathering the objects sequentially, thus it's important to break any apparent logical continuity in the sequence.)

Message was edited by:

30goldbe

[948 byte] By [30goldbea] at [2007-11-26 15:32:34]
# 1
Since you need to be able to invert the value and get back the original it is called 'encryption'! I suspect you knew that! If you did not have to invert it then it would be a hashing such as SHA-1.
sabre150a at 2007-7-8 21:49:33 > top of Java-index,Security,Cryptography...
# 2

> Since you need to be able to invert the value and get

> back the original it is called 'encryption'! I

That's why I posted in this forum! ;)

I would be tempted to do the following (but I was hoping there was a faster method):

Let N be the original integer. Let p be a large prime number (around 10 million). Let q be a small integer greater than 1, prime with respect to (p-1).

public Long firstScramble (Long N) {

return (N^q) % p;

}

I could then use the hexadecimal version of the result which would result in the desired string. To unscramble, it's just a matter of finding the integer r such that (r*q) % (p-1) = 1...

(It would be possible to speed the above calculation with a for loop...)

Is there a faster method in one of the cryptography packages?

Message was edited by:

30goldbe

Message was edited by:

30goldbe

30goldbea at 2007-7-8 21:49:33 > top of Java-index,Security,Cryptography...
# 3
Faster than your method? Probably not. More secure? Certainly. I don't really know what you expect as an answer.
sabre150a at 2007-7-8 21:49:33 > top of Java-index,Security,Cryptography...
# 4

> Faster than your method? Probably not. More secure?

> Certainly.

Thanks! Already that answer gives me some pointers as to what I can expect.

If I could ask one more thing: would you be willing to suggest a few (2 or 3) classes I might want to look into as possible "en/de-cryptic" black boxes? I'd happily take it from there!

(There's so much stuff in the Java libraries that I could waste a lot of time just researching where to begin!)

30goldbea at 2007-7-8 21:49:33 > top of Java-index,Security,Cryptography...
# 5

It is not a matter of just suggesting classes. You need to understand the JCE framework and then you will have access to several algorthms. If you use a block cipher then you could use DES to get an 8 byte result or AES to get a 16 byte result. You may want to look at using a stream cipher such as RC4 but which ever way you go you will need to understand the JCE framework.

Use Google to find a JCE tutorial.

sabre150a at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 6
Thank you! I'll follow your advice!
30goldbea at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 7
Just a note: I would never use DES because of its only 56-bit long key. It's simply no more up to date. It may be a little bit faster than the others but who cases (normally AES and other modern ciphers are fast enough).
Maaartina at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 8

> Just a note: I would never use DES because of its

> only 56-bit long key. It's simply no more up to date.

> It may be a little bit faster than the others but who

> cases (normally AES and other modern ciphers are fast

> enough).

Considering the context, this is a little dogmatic! DES was suggested because it has an 8 byte block and not for it's security. Alos, what the OP is suggesting is far less secure.

sabre150a at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 9

Of couse, in this context is DES perfectly ok, I wanted just point out, that DES ist out of date (and too many people still use it).

I have my own question: Are you aware abou any cipher, transforming e.g., a six digit decimal number to another one? I need to keep the result in the original range 0 .. 999999.

Or is there a way, how to encrypt e.g. a 3 byte number into another one... RC4 would NOT do, since I need to encrypt dozens of numbers using the same key.

Maaartina at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 10

> Or is there a way, how to encrypt e.g. a 3 byte

> number into another one... RC4 would NOT do, since I

> need to encrypt dozens of numbers using the same key.

You should start your own topic since this is only vaguely related to the original.

What about RC4 stops it being used dozens of times with the same key?

sabre150a at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 11

Ok, I just started the topic

http://forum.java.sun.com/thread.jspa?threadID=5132016

RC4 is a Vernan cipher, actually it's just xoring the plaintext with the output of a PRNG. If you use the equally seeded PNRG for two plaintexts, then the attacker makes a XOR of the two ciphertexts and you lose, since it equals the XOR of the two plaintexts, thus revealing a lot of information, making statistical analysis quite simple.

Maaartina at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...
# 12

> Ok, I just started the topic

> http://forum.java.sun.com/thread.jspa?threadID=5132016

>

>

> RC4 is a Vernan cipher, actually it's just xoring the

> plaintext with the output of a PRNG. If you use the

> equally seeded PNRG for two plaintexts, then the

> attacker makes a XOR of the two ciphertexts and you

> lose, since it equals the XOR of the two plaintexts,

> thus revealing a lot of information, making

> statistical analysis quite simple.

You are right! I had forgotten!

sabre150a at 2007-7-8 21:49:34 > top of Java-index,Security,Cryptography...