Skip to content

Instantly share code, notes, and snippets.

@daCyuubi
Created February 1, 2018 23:08
Show Gist options
  • Save daCyuubi/67e97c6877cf4b1637adc10852fd731d to your computer and use it in GitHub Desktop.
Save daCyuubi/67e97c6877cf4b1637adc10852fd731d to your computer and use it in GitHub Desktop.
<?php
function prudp_calculate_checksum($hex) {
$hex_dump = str_split($hex, 2); // split hex string into an array every 2 parts
var_dump($hex_dump);
$checksum_result = 1; // 1 because the final output of the checksum is a bit off
foreach ($hex_dump as &$value) { // foreach hex stuff
$checksum_result += hexdec($value); // sum up of all the hex in decimal
}
$checksum_result = $checksum_result % 256; // mod by 256, this is where the magic begins
return dechex($checksum_result); // this should probably be hex?
}
$packet_uncalculated = 'afa140' . str_repeat('00', 12);
$packet_checksum = prudp_calculate_checksum($packet_uncalculated);
$packet_calculated = $packet_uncalculated . $packet_checksum;
echo($packet_calculated);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment