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