Sign in to follow this  

Generating unique number from two other unique numbers

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites

This topic is 4811 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this