Hello Charles
i dug thru' the O2 example codes and O2 forum and found 2 hashing functions which are listed below
normal O2 hash code
'===================================
' O2 Hash
' This gives a very huge number which is more difficult
' for comparison purposes than O2 ASM Hash
Function O2Hash(string GivStr) as sys
if not GivStr then
' exit if blank string
return 0
end if
byte b at (strptr GivStr)
sys LengS=len GivStr
sys a=LengS*256
sys i
for i=1 to LengS
a = a xor 0x3a575a73 xor b
rol a,18
@b++
next
return a
End Function
O2 Hash in assembly
'===================================
' O2 ASM Hash
' https://www.oxygenbasic.org/forum/index.php?topic=586.msg6461#msg6461
' reply #4 this is the better Hashing as it gives a smaller number
Function O2HashASM(string GivStr) as Sys
xor eax,eax
mov edx, [GivStr] ' name pointer
mov ecx, [edx-4] ' length
(
cmp ecx,0
jnz exit
return 0 'EMPTY WORD WILL TRIGGER HASHCODE ERROR LATER
)
mov ah, cl ' assume max length 255
(
xor al, [edx]
xor eax,0x3a575a73
rol eax,18
inc edx
dec ecx
jnz repeat
)
return eax
End Function
seemingly the O2 Hash in ASM is a better one amongst these 2 sets of codes as
it gives a hash some thing like 289133459 as compare to the normal hash which give huge results of 5.19993 E+18
What do you suggest to use O2 hash in ASM or O2 hash normal ?
so far i have tested both functions out and found no problem or collision errors from small strings ( 6 letters) to very
huge strings ( 83 MB file strings )
Hi Chris,
The assembler version always generates a 32bit hash, whereas the basic version generates a 64bit hash in 64bit mode.
How unique does your hash need to be?
Thanxx a lot Charles
so far from my tests results (over 100 strings and files) , the O2 Hash ASM did not fail (ie. no collisions ) and pretty fast too
i will stick to O2 Hash ASM as it provides unique and manageable numbers.
i was using FNV hashing in PB which is not so good as strings with less than 7 characters encounter collisions
i wonder what method or algorithm that this O2 ASM hash was based on such as SHA256 , RC4 or AES ?
It's just cheap and cheerful hashing for data storage and id. Not suitable for cryptography.
Nevermind, my work does not need sopshicated cryptography, i just need to have a simple and
normal check on some file sizes using normal hashing method as effected by O2 ASM Hash.
not for those server or database logins and password authentication methods which i don't use at all
so this hash function will do