hi.
this WORKS but the decrypt is NOT every elegant - and I know some of you smart guys understand XOR and flipping bits etc. for this type of application. here is the function:
function symmetrical_encrypt($options=array()){
global $MASTER_PASSWORD;
extract($options);
if(!$action)$action='byte_encrypt';
if(!$key)$key=md5($MASTER_PASSWORD);
if(!function_exists('byte_encrypt')){
function byte_encrypt($base,$key){
return $base ^ $key;
}
function byte_decrypt($result, $key){
/*
!!! this is the part I would like to improve..
!!!
*/
$a=str_pad(base_convert(ord($result),10,2),8,0,STR_PAD_LEFT);
$b=str_pad(base_convert(ord($key),10,2),8,0,STR_PAD_LEFT);
for($i=0; $i<8; $i++){
$s.=($a{$i} xor $b{$i}) ? 1 : 0;
}
return chr(base_convert($s,2,10));
}
}
if($action=='byte_decrypt' && !$suppressBase64)$string=base64_decode($string);
for($i=0;$i<strlen($string);$i++){
$out.=$action($string{$i}, substr($key,fmod($i,strlen($key)),1));
}
if($action=='byte_encrypt' && !$suppressBase64)$out=base64_encode($out);
return $out;
}
//example
$encrypted=symmetrical_encrypt( array(
'string'=>'how are you doing bob',
'key'=> 'G48COX4E',
));
echo $decrypted=symmetrical_encrypt( array(
'string'=>$encrypted,
'key'=>'G48COX4E',
'action'=>'byte_decrypt',
));
theoretically byte_decrypt() is probably a simple ^ operation to remove the overlay key's effect but I couldn't make it work. Please help if you know the correct way to decrypt in strict logical expressions