Generating unique number from two other unique numbers

Started by
4 comments, last by GameDev.net 19 years, 6 months ago
I would like to generate a unique number from two other unique numbers. With the two input numbers, one is a customer ID number (e.g. 23 = "John Kerry", 97 = "George Bush" etc.) and the other number is a promotion ID (e.g. 5 = "October two-for-one sale", 8 = "Summer free shipping promotion" etc.) The two input numbers are NOT unique against themselves i.e. I could have a customer # 23 redeeming promotion # 23. They are only unique amongst themselves. The end goal is that from a generated number I am able to decode back the customer ID and promotion ID. What I require of the output number is that: - all numbers generated are unique - is scrambled (simple encryption) - it includes a checksum (digits or bits) - is capable of future expansion - the number uses smallest amount of digits possible (say 6 or 8 digits) - is all numeric, no alphabetic chars - number capable of use as a barcode (I'm not sure if numbers need to have a certain format for barcodes, e.g. I'm making up a rule - "numbers can't have two consecutive digits the same") - and any thing else I may have missed By "future expansion", I mean that if I ever had to change the encoding scheme, the number would be able to indicate what scheme it used. My initial thoughts were to think of the maximum size of number of customers and promotions I would ever gather. So if I decided on an upper limit of 65536 promotions (16 bits) and 1 bit as a future expansion bit (if set then treat number as a different scheme) and X number of bits as checksum/parity etc. I could then generate a number by doing something like: promotion number + (customer number * 65536) = the number and then also incorporate the 'expansion' bit and checksum, and then finally scramble it with some simple algorithm, say XOR etc. Can anybody assist with any further advice and/or links to online articles? Thanks in advance, Simon.
Advertisement
Sounds to me like you pretty much know what you're doing already.
Thanks - although it does seem I know the solution, I'm just making sure there's no gotchas - such as the barcode issue and getting the digit count as small as possible.
If you want something mush better than an xor for encryption, yet almost as easy, try substitution encoding and decoding tables, say 16 or 256 bytes with a different table offset for each nibble.
I agree that it sounds like you're pretty much sussed.
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms
Quote:
- number capable of use as a barcode (I'm not sure if numbers need to have a certain format for barcodes, e.g. I'm making up a rule - "numbers can't have two consecutive digits the same")


There are some rules about barcodes. The last digit is a checksum of the other digits, and not actually a part of the bar code itself. How the checksum is calculated differs (i think) between EAN and UPC. I don't remember exactly how it is calculated, but google should be able to find it easily.
Also, in EAN (don't know about UPC) the first part of the code alsu usually represents the country of origin and manufacturer - whether this is applicable to your use or not i don't know.
Why dont you just append the numbers together, do some crazy encryption, like double it or whatever, Something you can decode then append your checksum and formating for the barcode...

Like 23 and 97 would be XXXCC04794XXX 'X' = the barcode stuff, and 'C' is your checksum
and 99, 99 would be XXXCC19998XXX....

If thats not what you are asking im sorry.

This topic is closed to new replies.

Advertisement