Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $crc32_table = array_fill(0, 256, 0);
- $POLY = 0xC00D3BAD; // you know the poly dude!!
- function build_crc_tables() {
- global $crc32_table, $POLY;
- for ($i=0; $i < 256; $i++) {
- $fwd = $i;
- $j = 8;
- while ($j > 0) {
- if (($fwd & 1) == 1)
- $fwd = ($fwd >> 1) ^ $POLY;
- else
- $fwd >>= 1;
- $crc32_table[$i] = $fwd;
- $j--;
- }
- }
- }
- function custom_crc($s) {
- global $crc32_table;
- $crc = 0xffffffff;
- foreach (str_split($s) as $v) {
- $crc = ($crc >> 8) ^ $crc32_table[$crc & 0xff ^ ord($v)];
- }
- return $crc ^ 0xffffffff;
- }
- function digest($crc) {
- return dechex($crc);
- }
- build_crc_tables();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement