Skip to content

Adding ELFHash Algorithm #6731

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Oct 30, 2022
Merged
23 changes: 23 additions & 0 deletions hashes/elf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
def elf_hash(data):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: elf_hash. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: elf_hash. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: data

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: elf_hash. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide type hint for the parameter: data

"""
Implementation of ElfHash Algorithm, a variant of PJW hash function.

Returns:
[int] -- [32 bit binary int]
>>> elf_hash('lorem ipsum')
253956621
"""
hash = x = i = 0
for i in range(len(data)):
hash = (hash << 4) + ord(data[i])
x = hash & 0xF0000000
if x != 0:
hash ^= x >> 24
hash &= ~x
return hash


if __name__ == "__main__":
import doctest

doctest.testmod()