I have to encrypt and decrypt a 10 digit number to get a unique value. I want the results less than 6 digit/char long. I tried something like following.
The algorithm is
Pick a 8 or 9 digit number at random, say 839712541.
Then, take your order number's binary representation (for this example,
I'm not using 2's complement), pad it out to the same number of bits (30), reverse it,
and xor the flipped order number and the magic number.
To get the order numbers back, xor the output number with your magic number,
convert to a bit string, and reverse.
The above code was just used as an example and tried to implement it to see it running successfully. Can anyone help me correct the above results and get them right and
Find or have a better soluiton to my requirements. I am badly in need for the same. I looked around over internet but couldn't find any thing helpful.
Your help and guidens can be of great help.
If you really require <6 then you need 7 bits a time, requiring a 128-character "alphabet".
If the magic # has to be all digits (that is, 0 to 9) AND must be guaranteed unique, then you're asking for the impossible.
Henry Wong wrote:You are not being consistent. Going one direction, you used the reverse() method. Going the other direction, you used the reverseBytes() method. Since these two methods do two different things, it would make sense that you don't get the original number back.
Oh Thanks Henry, That mistake gave me the correct ans back. Now, can you help out me to get the results as only 6 numeric/alphanumeric unique code. Like Xor with any number gives unique results, but at presnet the value returned is quiet long, plus my number will be a 10 digit number not just 1 or 2. I want to reduce it to 3-4 numeric/alphanumeric unique code.
Now, can you help out me to get the results as only 6 numeric/alphanumeric unique code.
Nope. Not usless you change the algorithm. Your algorithm is very specific. It is not possible to take any number, do an XOR, and a bit reverse, and guarantee the result to less than 6 digits. (well, actually you can, if you don't care to decrypt it ... )
Here is another way to think about it... You have a 10 digit number. There are 10,000,000,000 possible 10 digit numbers. You need to generate unique numbers. So, your algorithm needs to generate 10,000,000,000 unique (ie. different) numbers. There are only 1,000,000 possible six digit numbers. Can you assign 10,000,000,000 unique numbers from a pool of 1,000,000 numbers? With any algorithm?
Henry, I need the code (number) to be unique, it may be alphanumeric. And also that should be decryptable to provide the same original number. Since decrypt is associated, that's where I am finding difficult to generate unique code of 6 chars of length.
John the unique code can be anything but should be max 6 chars. The magic number can also be anything, SECURE algorithm is also not required it should just solve the purpose. If the magic # is alpha or alpha numeric, then how do you plan to work around. Can you throw some light on this and Log_10 and Log_36 with maybe a eg statement.
Security issue coming up, is their any other way to do the same with any other resources.
On the other hand, if you allow for 6 characters, then it is possible, and if you use Campbell's 64 character alphabet it is easy.