1. 程式人生 > >使用CRC32 校驗png資料

使用CRC32 校驗png資料

這是php檔案
<?php
$checksum = crc32(file_get_contents('a.data'));
$t=int32_to_hex($checksum);
$n=strlen($t);
$crc='';
file_put_contents("b.data",'');
for($i=0;$i<$n;$i+=2)
{
// file_put_contents("b.data",pack('C',hexdec('0x'.substr($t,$i,2))),FILE_APPEND);
 $crc.=pack('C',hexdec('0x'.substr($t,$i,2)));
}
file_put_contents("b.data",$crc);
function int32_to_hex($value) { 
  $value &= 0xffffffff; 
  return  str_pad(strtoupper(dechex($value)), 8, "0", STR_PAD_LEFT); 
} 
?>

a.data是要校驗的資料

504C54452C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC2C82FC


png操作方法請看

http://blog.csdn.net/bisword/article/details/2777121

http://www.ismyway.com/png/png-struct1.htm

http://mxdxm.iteye.com/blog/787107