Rentian,
You’re going to kick yourself but the first thing you need to do is move the set sum 0 outside of the for loop. That will fix it so that it will return the correct integer value. Expr always returns a numeric result so something like expr 0x21 * 0x02 returns 66 instead of 0x42. You will need to use the format command to return a Hex string as so:
set sum [format 0x%08x [expr ($sum + ([scan [string index $str $i] %c] * (($i + 1) << 4))) % 0x10000]]
John Mercogliano
Semi Retired, contractor
Hampton Roads, VA