Click to See Complete Forum and Search --> : Algorithm to create unique value of characters


marbles
April 3rd, 2010, 09:37 PM
Is there some algorithm to somehow encrypt characters into a single value for later comparison with other character sequence with the same length?
no duplicates allowed: f.e. [a,b,c] = X, where X is the result of some operation to make those characters unique.

Adding up all ascii values doesn't work: [d = 100, e = 101] and [c = 99, f = 102]. Obviously both add up to 201 with different letters.

Is there an algorithm with some operations that would make that value unique?

Thanks!
marbles

MrViggy
April 5th, 2010, 11:11 AM
SHA1 (http://en.wikipedia.org/wiki/SHA1) is one algorithm that might work for you.

Viggy

nuzzle
April 6th, 2010, 02:49 PM
Is there an algorithm with some operations that would make that value unique?


Why not just store the characters as a string. It's a single value and it's unique.

marbles
April 6th, 2010, 04:43 PM
Why not just store the characters as a string. It's a single value and it's unique.

The problem is that the order doesn't matter: [a,b,c] and [b,c,a] should result in the same value. I tried generating all permutations and compare with a given string. But that gets huge the more characters there are.

Thanks

nuzzle
April 6th, 2010, 04:56 PM
The problem is that the order doesn't matter: [a,b,c] and [b,c,a] should result in the same value.


Just sort the strings. Then both [a,b,c] and [b,c,a] will turn out [a,b,c] and be equal.