Esempio n. 1
0
 public function testGenerate()
 {
     $finger = Fingerprint::generate();
     $this->assertNotNull($finger);
     // Make sure it generates the same value
     $this->assertSame($finger, Fingerprint::generate());
 }
 function getRequestParameters()
 {
     $params = $this->getRawParameters();
     $fingerprintOrder = array_merge(['customerId', 'shopId', 'password', 'secret', 'language'], $this->fingerprintOrder);
     $requiredParameters = array_merge(['customerId', 'requestFingerprint', 'password', 'language'], $this->requiredParameters);
     switch ($this->getParam('fundTransferType')) {
         case FundTransferType::EXISTINGORDER:
             $fingerprintOrder[] = 'sourceOrderNumber';
             $requiredParameters[] = 'sourceOrderNumber';
             break;
         case FundTransferType::MONETA:
             $fingerprintOrder[] = 'consumerWalletId';
             $requiredParameters[] = 'consumerWalletId';
             break;
         case FundTransferType::SEPA_CT:
             $fingerprintOrder[] = 'bankAccountOwner';
             $fingerprintOrder[] = 'bankBic';
             $fingerprintOrder[] = 'bankAccountIban';
             $requiredParameters[] = 'bankAccountOwner';
             $requiredParameters[] = 'bankBic';
             $requiredParameters[] = 'bankAccountIban';
             break;
         case FundTransferType::SKRILLWALLET:
             $fingerprintOrder[] = 'consumerEmail';
             $requiredParameters[] = 'consumerEmail';
             $requiredParameters[] = 'customerStatement';
             break;
     }
     $params['requestFingerprint'] = Fingerprint::fromParameters($params)->setContext($this->getContext())->setFingerprintOrder($fingerprintOrder);
     $this->assertParametersAreValid($params, $requiredParameters);
     return $params;
 }
 /**
  * This method applies the Winnowing Algorithmn described at the article
  * `Winnowing: Local Algorithms for Document Fingerprinting` by Saul Schleimer,
  * Daniel S. Wilkerson, and Alex Aiken. It consists in extracting the smallest hash
  * in a window of characters taken directly from the text. This way it's possible to
  * identify similarities across documents since you can have different individual hashs
  * in a very similar sequence of hashs. For more information read the article.
  *
  * @public
  * @param $documentContent the document text
  * @return {array} an array of Fingerprints
  */
 public function extractFingerprint($documentContent)
 {
     $fingerprints = array();
     $contentLength = strlen($documentContent);
     $hashCount = $contentLength - $this->k;
     $windowSize = $this->threshold - $this->k + 1;
     for ($i = 0; $i < $hashCount; $i++) {
         $window = array();
         for ($j = $i; $j < $i + $windowSize; $j++) {
             $value = substr($documentContent, $j, $this->k);
             $window[$j] = hash('md5', $value, false);
         }
         reset($window);
         $min = key($window);
         $fingerprint = $window[$min];
         foreach ($window as $index => $hash) {
             if ($hash <= $fingerprint) {
                 $min = $index;
                 $fingerprint = $hash;
             }
         }
         $fingerprints[$min] = $fingerprint;
     }
     $ret = array();
     $normalizedLocation = 0;
     foreach ($fingerprints as $loc => $hash) {
         array_push($ret, Fingerprint::fill($hash, $loc, $normalizedLocation++));
     }
     return $ret;
 }
Esempio n. 4
0
 public function isEquals(Fingerprint $fingerprint)
 {
     return $this->getHash() === $fingerprint->getHash();
 }