Skip to content

Commit

Permalink
spamsum :: setblocksize
Browse files Browse the repository at this point in the history
  • Loading branch information
tdebatty committed Dec 16, 2014
1 parent 8896805 commit c027ef2
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/webd/language/SpamSum.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit c027ef2

Please sign in to comment.