Sorry if the title doesn’t make sense. Basically I have a series of strings that are 10-60 characters long. The problem being is the service I have to use only accepts strings up to 25 so I need a way to convert the strings I have to 25 characters or less, send it off and when I get the results back be able to convert it back to the original id.
Example:
id = "this_is_a_test_account_that_is_longer_than_allowed"
id = contract(id)
// id = "DSFK23478JDSFHGW874"
id = expand("DSFK23478JDSFHGW874")
// id = "this_is_a_test_account_that_is_longer_than_allowed"
No, you can’t do this. It’s basically asking for a compression algorithm which will always make things smaller – it’s just not going to happen. At least not in a general sense, due to the pigeonhole principle. (In particular, think about every hex string of the right length. You’ve got to store all of those, so suppose each one just goes to itself. Now, you’ve got to be able to store other strings too – but by definition you’ve run out of valid outputs.)
On the other hand, if you have a server which could generate a UUID for any string and store the string, you could then look that UUID up again later. Would that work for your situation?
(Of course it doesn’t have to be a UUID – you could just start with 0 and work your way up…)
If you know all the strings beforehand, that’s just a special-case of this situation: create a hard-coded bi-directional map for all the strings, generating the output uniquely in some fashion (e.g. with UUIDs).