Question

Here is what I need (language: C# 4):

I am building a system where you can submit complaints. After complaint has been submitted you are given a unique 9 digits number that identifies your complaint in the system.

For security (security through obscurity) purposes I do not want ticket IDs to be sequential. But I do want to use database to generate sequential id.

So what I need is a injective function that is fast both ways: sequential number to my ticket id, and back from ticket id to the sequential number.

So that my ticketId in database is sequential, but before showing it to a user I will obfuscate it, similarly, when I get a number back from the user, I de-obfuscate it and use it to look up complaint in the database.

The obfuscation part does not need to be too complicated, just "not apparent enough" for general public.

For example I could simply change bitness of the value, which will get me (for 8-bit values):

0 -> 0
1 -> 128
2 -> 192
3 -> 64
4 -> 160
5 -> 96

etc.

Was it helpful?

Solution

I think you can solve this problem perfectly: Encrypt the ticket number with a constant key. There is a 32-bit block-size block cipher that you can use.

OTHER TIPS

I would suggest something along the lines of symmetric encryption. For example, if you apply the substitution and diffusion steps of the DES encryption algorithm, you can get a number that can be quickly mapped back and forth but difficult to find a pattern. It is almost the same as your example but the S-Box and P-Box values are proved to be effective against cryptanalysis.

Why not just do something like this:

SHA1 your number, then store it in a table in your database along with your sequential number. Then when you receive the hash, just look up the sequential number in the database.

FYI, this is not really security. You should implement a real password system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top