diff --git a/src/webd/language/SpamSum.php b/src/webd/language/SpamSum.php index 24d7b48..1e4eb18 100644 --- a/src/webd/language/SpamSum.php +++ b/src/webd/language/SpamSum.php @@ -28,9 +28,10 @@ public static function Hash($string) { const B64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; protected $SPAMSUM_LENGTH = 64; - protected $MIN_BLOCKSIZE = 3; protected $LETTERS = 64; protected $BLOCKSIZE = 0; + protected $MIN_BLOCKSIZE = 3; + protected $auto_blocksize = true; protected $left; protected $right; @@ -47,6 +48,16 @@ public function SetMinBlocksize($s) { $this->MIN_BLOCKSIZE = $s; } + /** + * Set the blok size manually, so that it won't be computed from the length of + * the string + * @param type $s + */ + public function SetBlockSize($s) { + $this->BLOCKSIZE = $s; + $this->auto_blocksize = false; + } + /** * * @param type $string @@ -65,7 +76,7 @@ public function HashString($string) { unset($in[count($in)]); // Guess a a reasonable block size - if ($this->BLOCKSIZE == 0) { + if ($this->auto_blocksize) { $this->BLOCKSIZE = $this->MIN_BLOCKSIZE; while ($this->BLOCKSIZE * $this->SPAMSUM_LENGTH < $length) { @@ -135,8 +146,9 @@ public function HashString($string) { /* Our blocksize guess may have been way off - repeat if necessary */ - if ($this->BLOCKSIZE > $this->MIN_BLOCKSIZE - && $j < $this->SPAMSUM_LENGTH / 2) { + if ($this->auto_blocksize + && $this->BLOCKSIZE > $this->MIN_BLOCKSIZE + && $j < $this->SPAMSUM_LENGTH / 2) { $this->BLOCKSIZE = $this->BLOCKSIZE / 2; goto again;