CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2009
    Posts
    10

    Algorithm to create unique value of characters

    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

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Algorithm to create unique value of characters

    SHA1 is one algorithm that might work for you.

    Viggy

  3. #3
    Join Date
    May 2009
    Posts
    2,413

    Re: Algorithm to create unique value of characters

    Quote Originally Posted by marbles View Post
    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.
    Last edited by nuzzle; April 6th, 2010 at 02:58 PM.

  4. #4
    Join Date
    Dec 2009
    Posts
    10

    Re: Algorithm to create unique value of characters

    Quote Originally Posted by nuzzle View Post
    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

  5. #5
    Join Date
    May 2009
    Posts
    2,413

    Re: Algorithm to create unique value of characters

    Quote Originally Posted by marbles View Post
    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.
    Last edited by nuzzle; April 6th, 2010 at 05:03 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured