# proving algorithm to check if two strings are anagrams-

I have this idea (using C language) for checking for two string if they are anagrams-

1. if the length of the strings is the same (its only a-z and A-Z).

2. sum of ASCII value of all chars in a string is the same for both strings.

3. multiplication of ASCII value of all chars in a string is the same for both strings.

I believe that if all three are correct it must be an anagram but I cannot prove it.. since I have no math background.. can any one prove it or contradict it?

(other solutions for this problem are not necessery)

-

A minimal counterexample is "BPT" (ASCII $66$, $80$, $84$) and "FHX" (ASCII $70$, $72$, $88$). They're the same length, the sums are both $230$, and the products are both $443520$. As mentioned in the other answer, you will probably need all $n$ symmetric functions of the ASCII codes to correctly identify all non-anagrammatic pairs of length $n$. For instance, for $n=3$, in addition to $x_1+x_2+x_3$ and $x_1 x_2 x_3$, you can include $x_1 x_2 + x_1 x_3 + x_2 x_3$ in your "key".
If the string has length $n$, you most probably need all $n$ symmetric functions of the chars, just the two you mentioned won't do.
Try to find an example with $n=3$.