Created
February 1, 2018 23:08
-
-
Save daCyuubi/67e97c6877cf4b1637adc10852fd731d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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