From ea4f18581054d949a109e54dd85c68a29ab6873d Mon Sep 17 00:00:00 2001 From: Kevin Jahns Date: Thu, 22 Jun 2023 17:14:11 +0200 Subject: [PATCH] [rabin] update comments --- hash/rabin.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/hash/rabin.js b/hash/rabin.js index 90f0a28..d5690f1 100644 --- a/hash/rabin.js +++ b/hash/rabin.js @@ -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' @@ -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() } @@ -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 () { @@ -87,8 +88,6 @@ export class RabinEncoder { } /** - * Basically an exact copy of the Encoder, but inlined. - * * @param {Uint8Array} irreducible * @param {Uint8Array} data */