XR3X

Jump to content


Photo

Hash function in various language (FASM x86, x86_64, macro language/JavaScript))


  • You cannot start a new topic
  • Please log in to reply
3 replies to this topic

#1 0xDADA11C7

0xDADA11C7

    Beginner

  • Members +
  • 12 posts
  • LocationUkraine

Posted 11 December 2014 - 12:25 AM

Hash function for null terninated strings in various languages

FASM macro language

Please Login or Register to see this Hidden Content

FASM x64


Please Login or Register to see this Hidden Content

FASM x86


Please Login or Register to see this Hidden Content

JavaScript


Please Login or Register to see this Hidden Content

Please Login or Register to see this Hidden Content


Edited by 0xDADA11C7, 11 December 2014 - 12:29 AM.

  • Hess likes this

#2 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 11 December 2014 - 11:16 AM

Well there are various reasons why this hashing function isnt good. First of all, the x86 asm is horrible. Seriously. Its bloody beginners code for sure. But it seems like another guy did the x64 version because it looks way better.

My main point of critics is the algorythm itselve. It doesn't provide unique enough hashes. There is a much more simplier way. Hash = 31 * hash + char. Instead of 31 you can choose any prime.

#3 0xDADA11C7

0xDADA11C7

    Beginner

  • Members +
  • 12 posts
  • LocationUkraine

Posted 11 December 2014 - 11:40 AM

It`s all my work, but x86 code generated from pseudocode. In that time i did learn code generation with random commands.

For  example:

pseudocode compare register to zero can  be:

  • cmp regiser, 0x0
  • test register, register
  • cmp register, register

pseudocode load 0 to register can be:

  • xor register, register
  • sub register, register
  • mov register, 0
  • push 0 /pop register

Quote

My main point of critics is the algorythm itselve. It doesn't provide unique enough hashes. There is a much more simplier way. Hash = 31 * hash + char. Instead of 31 you can choose any prime.

Why do you think what your algo has less collisions? Where i can read about it?



#4 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 11 December 2014 - 01:47 PM

Please Login or Register to see this Hidden Content



This algo is for example used in the Java String hashcode function. If you search for optimal algorythms the Java implementations are always good to take a look at.

Try it out and write an Article about it. Maybe your algorythm is even better! But I think multiplying with primes is more effective than rotating.
  • 0xDADA11C7 likes this