Advertisement
KeyStrOke

sdfdsjiodjf

Apr 12th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. <?php
  2.  
  3. $crc32_table = array_fill(0, 256, 0);
  4. $POLY = 0xC00D3BAD; // you know the poly dude!!
  5.  
  6. function build_crc_tables() {
  7. global $crc32_table, $POLY;
  8. for ($i=0; $i < 256; $i++) {
  9. $fwd = $i;
  10. $j = 8;
  11. while ($j > 0) {
  12. if (($fwd & 1) == 1)
  13. $fwd = ($fwd >> 1) ^ $POLY;
  14. else
  15. $fwd >>= 1;
  16. $crc32_table[$i] = $fwd;
  17. $j--;
  18. }
  19. }
  20. }
  21.  
  22. function custom_crc($s) {
  23. global $crc32_table;
  24. $crc = 0xffffffff;
  25. foreach (str_split($s) as $v) {
  26. $crc = ($crc >> 8) ^ $crc32_table[$crc & 0xff ^ ord($v)];
  27. }
  28. return $crc ^ 0xffffffff;
  29. }
  30.  
  31. function digest($crc) {
  32. return dechex($crc);
  33. }
  34. build_crc_tables();
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement