Created
January 29, 2010 19:49
-
-
Save pifantastic/290042 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 | |
// NOTE: you can use actionscript's String.fromCharCode() in place of php's chr() | |
// NOTE: you can use actionscript's parseInt() in place of php's hexdec() | |
$md5 = md5("hello"); // php's md5() returns a string | |
$n = 123456789; | |
var_dump(pack("H*", $md5) === packMD5($md5)); // output: true | |
var_dump(pack("VXxx", $n) === packVXxx($n)); // output: true | |
function packMD5($string) { | |
$binary_string = ''; | |
for ($x = 0; $x < strlen($string); $x += 2) { | |
$binary_string .= chr(hexdec($string[$x] . $string[$x + 1])); | |
} | |
return $binary_string; | |
} | |
function packVXxx($n) { | |
$binary_string = chr($n & 0x000000ff); | |
$binary_string .= chr(($n >> 8) & 0x000000ff); | |
$binary_string .= chr(($n >> 16) & 0x000000ff); | |
return $binary_string . chr(0) . chr(0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment