I\'m trying to develop a system that can change my string into a unique integral value, meaning say for example the word \"account\" has an encrypted numerical value of 0891
This is not possible with the constraints you have given, unless you impose a maximum length.
Assume that k("a")
and k("b")
are the codes of these two strings.
With your constraints, you are looking for a unique integer number that falls inbetween these two values, but k("a") < k("a....a") < k("b")
. As there is an infinite number of strings of style "a....a"
(and "akjhdsfkjhs"
) that would need to fit inbetween the two codes, such an order preserving general, unique, fixed-length code cannot exist for strings of arbitrary length. Because you would need as many integers as strings, and since strings are not bounded by length this cannot work.
Drop either general (so don't allow inserting new strings), unique (allow collissions - e.g. use the first four letters as code!), the unbounded length (to e.g. 3 characters) or the order-preserving property.