Skip to content
This repository has been archived by the owner on Sep 1, 2024. It is now read-only.

Commit

Permalink
Bug fix in djb2_hash
Browse files Browse the repository at this point in the history
  • Loading branch information
memN0ps committed May 27, 2024
1 parent 5b663d1 commit b66e5c0
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions shared/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,24 @@ impl ClientData {
/// * `u32` - The hash of the buffer.
pub fn djb2_hash(buffer: &[u8]) -> u32 {
let mut hash: u32 = 5381;
for &byte in buffer {
let char = if byte >= b'a' { byte - 0x20 } else { byte };
hash = (hash << 5).wrapping_add(hash).wrapping_add(char as u32);
let mut i: usize = 0;
let mut char: u8;

while i < buffer.len() {
char = buffer[i];

if char == 0 {
i += 1;
continue;
}

if char >= ('a' as u8) {
char -= 0x20;
}

hash = ((hash << 5).wrapping_add(hash)) + char as u32;
i += 1;
}
hash

return hash;
}

0 comments on commit b66e5c0

Please sign in to comment.