Skip to content

Commit

Permalink
[rabin] update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dmonad committed Jun 22, 2023
1 parent b7915f3 commit ea4f185
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions hash/rabin.js
Expand Up @@ -2,7 +2,7 @@
* @module rabin
*
* Very efficient & versatile fingerprint/hashing algorithm. However, it is not cryptographically
* secure.
* secure. Well suited for fingerprinting.
*/

import * as buffer from '../buffer.js'
Expand Down Expand Up @@ -34,10 +34,11 @@ const ensureCache = m => map.setIfUndefined(_precomputedFingerprintCache, buffer
const mBitShifted = buffer.shiftNBitsLeft(m, bit)
const bitShifted = 1 << bit
for (let j = 0; j < bitShifted; j++) {
// rest is already precomputed
// apply the shifted result (reducing the degree of the polynomial)
const msb = bitShifted | j
const rest = msb ^ mBitShifted[0]
for (let i = 0; i < byteLen; i++) {
// rest is already precomputed in the cache
cache[msb * byteLen + i] = cache[rest * byteLen + i] ^ mBitShifted[i]
}
// if (cache[(bitShifted | j) * byteLen] !== (bitShifted | j)) { error.unexpectedCase() }
Expand Down Expand Up @@ -74,7 +75,7 @@ export class RabinEncoder {
for (let i = 0; i < this.blen; i++) {
this.bs[(this.bpos + i) % this.blen] ^= this.cache[msb * this.blen + i]
}
// assert(this.bs[this.bpos] !== 0)
// assert(this.bs[this.bpos] === 0)
}

getFingerprint () {
Expand All @@ -87,8 +88,6 @@ export class RabinEncoder {
}

/**
* Basically an exact copy of the Encoder, but inlined.
*
* @param {Uint8Array} irreducible
* @param {Uint8Array} data
*/
Expand Down

0 comments on commit ea4f185

Please sign in to comment.