Example #1
0
 public function testHashing()
 {
     // https://github.com/froydnj/ironclad/blob/master/testing/test-vectors/crc24.testvec
     $this->assertEquals('b704ce', dechex(Crc24::hash('')));
     $this->assertEquals('f25713', dechex(Crc24::hash('a')));
     $this->assertEquals('ba1c7b', dechex(Crc24::hash('abc')));
     $this->assertEquals('dbf0b6', dechex(Crc24::hash('message digest')));
     $this->assertEquals('ed3665', dechex(Crc24::hash('abcdefghijklmnopqrstuvwxyz')));
     $this->assertEquals('4662cd', dechex(Crc24::hash('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')));
     $this->assertEquals('8313bb', dechex(Crc24::hash('12345678901234567890123456789012345678901234567890123456789012345678901234567890')));
     // https://github.com/alexgorbatchev/node-crc/blob/master/test/crc24.spec.coffee
     $this->assertEquals('8c0072', dechex(Crc24::hash('1234567890')));
 }
Example #2
0
 /**
  * @param string $input
  * @return string
  */
 private static function generateChecksum($input)
 {
     return substr(base64_encode(substr(pack('N', Crc24::hash($input)), 1)), 0, 4);
 }