Difference between revisions of "User talk:Timeslip"
Jump to navigation
Jump to search
→Possible Issue
imported>Timeslip (→Possible Issue: 64 bit ints) |
imported>MentalElf |
||
Line 63: | Line 63: | ||
:::[[User:Timeslip|Timeslip]] 04:04, 11 October 2006 (EDT): Yes, in C# longs are 64 bit. For languages without 64 bit integer support, you can just split the hash into two 32 bit ints, since the upper and lower DWORDs are calculated seperately. | :::[[User:Timeslip|Timeslip]] 04:04, 11 October 2006 (EDT): Yes, in C# longs are 64 bit. For languages without 64 bit integer support, you can just split the hash into two 32 bit ints, since the upper and lower DWORDs are calculated seperately. | ||
<pre> | |||
############################################################################# | |||
## Procedure: GenHash | |||
proc ::GenHash {HFile HExt} { | |||
set hash64 [expr wide(0)] | |||
set HFile [string tolower $HFile] | |||
set HExt [string tolower $HExt] | |||
set HFLen [string length $HFile] | |||
if { $HFLen > 0 } { | |||
set hash64 [expr wide([scan [string index $HFile [expr $HFLen - 1]] "%c"])] | |||
tk_messageBox -message [format "A> %08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
if { $HFLen > 2 } { | |||
set hash64 [expr {$hash64 + wide([scan [string index $HFile [expr $HFLen - 2]] "%c"] << 8)}] | |||
tk_messageBox -message [format "B> %08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
} | |||
set hash64 [expr {$hash64 + wide($HFLen << 16)}] | |||
tk_messageBox -message [format "C> %08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
set hash64 [expr {$hash64 + (wide([scan [string index $HFile 0] "%c"] << 24) & 0xFFFFFFFF)}] | |||
tk_messageBox -message [format "D> %08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
} | |||
if { $HFLen > 3 } { | |||
set hash64 [expr {$hash64 + ((wide([GenHash2 [string range $HFile 1 [expr $HFLen - 3]]]) & 0xFFFFFFFF) << 32)}] | |||
tk_messageBox -message [format "E> %08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
} | |||
if { [string length $HExt] > 0 } { | |||
set hash64 [expr {$hash64 + ((wide([GenHash2 $HExt]) & 0xFFFFFFFF) << 32)}] | |||
switch $HExt { | |||
".nif" { | |||
set i 1 | |||
} | |||
".kf" { | |||
set i 2 | |||
} | |||
".dds" { | |||
set i 3 | |||
} | |||
".wav" { | |||
set i 4 | |||
} | |||
default { | |||
set i 0 | |||
} | |||
} | |||
if { $i } { | |||
set a [expr {0xFF & ((($i & 0xFC) << 5) + (0xFF & (($hash64 & 0xFF000000) >> 24)))}] | |||
set b [expr {0xFF & ((($i & 0xFE) << 6) + (0xFF & $hash64))}] | |||
set c [expr {0xFF & (($i << 7) + (0xFF & (($hash64 & 0xFF00) >> 8)))}] | |||
set hash64 [expr {$hash64 - ($hash64 & 0xFF00FFFF)}] | |||
set hash64 [expr {$hash64 + ($a << 24) + $b + ($c << 8)}] | |||
} | |||
} | |||
tk_messageBox -message [format "%08X%08X" [expr {int($hash64 >> 32)}] [expr int($hash64)]] | |||
return $hash64 | |||
} | |||
############################################################################# | |||
## Procedure: GenHash2 | |||
proc ::GenHash2 {s} { | |||
for { set hash32 0; set i 0 } { $i < [string length $s] } { incr i } { | |||
set hash32 [expr $hash32 * 0x1003F] | |||
set hash32 [expr $hash32 + [scan [string index $s $i] "%c"]] | |||
} | |||
return $hash32 | |||
} | |||
</pre> |