Home > Software design >  Converting Specific data string to alphanumeric string with fixed length
Converting Specific data string to alphanumeric string with fixed length

Time:12-12

Consider I have a string which contains data such as ID,issuer Id, time stamp, and random string of any length, I need to convert this data into alphanumeric of fixed length example "U89B-AKFZ-GIM8-HYU3-ZCYH-V5PE-Y3G9-G1B0" and important I should able convert this back to the original data at the server.

I know hash algorithm will convert data to fixed length, but it is one way so cannot convert back to the actual data at sever

CodePudding user response:

Hash functions are one way encryption algorithms. If you want to decrypt your data at the server, you should use a two way algorithm like AES or DES.

CodePudding user response:

Basically, your request is to find a function f(s) that take a string s and losslessly transfer it into another string of certain length.

Theoretically speaking, this is just impossible. Your input space is of infinite size (any possible string in the world), but your output space is limited (let's say you want the fixed length is N, the space would only be 62^N). Hence, there's no such one-to-one mapping existed.

The only practical way to achieve that is to store your mappings. Then, there's ton of ways to convert a string into a fixed-length string. Hashing is a good way.

Usually, a simple schema in any relational database can be useful. We can have a table with just the HashValue and the OriginalValue column, having a unique index on the HashValue column for faster lookup.

  • Related