note 106216 added to function.crc32
| From: | arris at zsolttech dot com | Date: | Wed, 19 Oct 2011 12:17:00 +0000 |
| Subject: | note 106216 added to function.crc32 | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-183989@lists.php.net to get a copy of this message | ||
not found anywhere crc64 based on http://bioinfadmin.cs.ucl.ac.uk/downloads/crc64/crc64.c
.
(use gmp module)
<?php
/* OLDCRC */
define('POLY64REV', "d800000000000000");
define('INITIALCRC', "0000000000000000");
define('TABLELEN', 256);
/* NEWCRC */
// define('POLY64REV', "95AC9329AC4BC9B5");
// define('INITIALCRC', "FFFFFFFFFFFFFFFF");
if(function_exists('gmp_init')){
class CRC64{
private static $CRCTable = array();
public static function encode($seq){
$crc = gmp_init(INITIALCRC, 16);
$init = FALSE;
$poly64rev = gmp_init(POLY64REV, 16);
if (!$init)
{
$init = TRUE;
for ($i = 0; $i < TABLELEN; $i++)
{
$part = gmp_init($i, 10);
for ($j = 0; $j < 8; $j++)
{
if (gmp_strval(gmp_and($part, "0x1")) !=
"0"){
// if (gmp_testbit($part, 1)){ /* PHP 5
>= 5.3.0, untested */
$part = gmp_xor(gmp_div_q($part,
"2"), $poly64rev);
} else {
$part = gmp_div_q($part, "2");
}
}
self::$CRCTable[$i] = $part;
}
}
for($k = 0; $k < strlen($seq); $k++){
$tmp_gmp_val = gmp_init(ord($seq[$k]), 10);
$tableindex = gmp_xor(gmp_and($crc, "0xff"),
$tmp_gmp_val);
$crc = gmp_div_q($crc, "256");
$crc = gmp_xor($crc, self::$CRCTable[gmp_strval($tableindex, 10)]);
}
$res = gmp_strval($crc, 16);
return $res;
}
}
} else {
die("Please install php-gmp package!!!");
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 80.109.59.7
----
Manual Page -- http://www.php.net/manual/en/function.crc32.php
Edit -- https://master.php.net/note/edit/106216
Del: integrated -- https://master.php.net/note/delete/106216/integrated
Del: useless -- https://master.php.net/note/delete/106216/useless
Del: bad code -- https://master.php.net/note/delete/106216/bad+code
Del: spam -- https://master.php.net/note/delete/106216/spam
Del: non-english -- https://master.php.net/note/delete/106216/non-english
Del: in docs -- https://master.php.net/note/delete/106216/in+docs
Del: other reasons-- https://master.php.net/note/delete/106216
Reject -- https://master.php.net/note/reject/106216
Search -- https://master.php.net/manage/user-notes.php