Hello, if you know what this Subject line means I am impressed. If not then go to www.php.net and type in Pack in the Search functions list...read...and come back. Ok now that we are all refreshed with this. . HOW DO I USE IT!?! Lets say that I have a password of ABC123. I need to break it down to Binary form. How the heck can I use Pack to do it? It says it will take a string and break it to binary. Well how can I do that? Then use the unpack to get it back to its original form? PHP.net really didn't explain it very clearly in my mind. Hope someone can help. Thanks!
Ziggs
Example of Pack()
Here's a real rudimentary bit of code to pack text into a binary string with pack and unpack back into human readable chars:
<?
$str = "TEXT_MESSAGE";
//the easy part is 'encrypting' it...
for($i=0;$i<strlen($str);$i++) { $enc .= pack('C',decbin(ord(substr($str,$i,1)))); }
echo "Here's the binary output<br>\n";
echo $enc;
//now to decode...
$dump = unpack('C*',$enc);
echo "<p>Here is what we found...</p>\n";
print_r($dump);
foreach ($dump as $key=>$val) {
for ($x=0;$x<(8-strlen($val));$x++) { $val .= '0'; }
$test = chr(decbin($val));
if (ord($test) < 255) {
$str .= $test;
}
}
echo "<p>And here's the decrypted string: " . $str;
?>
...now, you can learn all about bitmasking by reading up on bitwise operators to shuffle the binary data to actually create a cypher.
Enjoy